399 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.

1512 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
+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' );
399 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.

1512 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
+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' );

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by