407 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Elite Author
  • Author Level 9
+7 more
EugeneO
says

I am playing around with post formats trying to set different post formats for standard posts and a custom post type. To do this I want to detect when we are on the custom post type Add New or Edit screen.

Detecting the Add New screen is simple as the post_type=custom_post_type_name query sting is set however I can not find a way to detect the post type on the edit screen of a custom post type.

Does anyone know of a way? I’ve been playing around with this for a while and can’t find a solution.

1565 posts
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 2
  • Featured Author
+2 more
OriginalEXE
says

Something like this?

function post_type_fetch( $query ) {

    if ( is_admin() ) {
        global $post;
        var_dump( get_post_type( $post ) );
    }

}

add_action( 'pre_get_posts', 'post_type_fetch' );
407 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Elite Author
  • Author Level 9
+7 more
EugeneO
says

That didn’t work for me. I think because I’m using the after_theme_setup hook to add theme support for post formats the $post global might not have been defined yet.

1565 posts
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 2
  • Featured Author
+2 more
OriginalEXE
says

How about this then:

function post_type_fetch() {

    if ( isset( $_GET['post'] ) ) {

        $post_type = get_post_type( intval( $_GET['post'] ) );
        var_dump( $post_type );

    }

}

add_action( 'after_setup_theme', 'post_type_fetch' );
by
by
by
by
by
by