375 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • United Kingdom
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • Exclusive Author
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.

1402 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
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' );
375 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • United Kingdom
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • Exclusive Author
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.

1402 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
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