389 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 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.

1484 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 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' );
389 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 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.

1484 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 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