[wp-hackers] identifying the current post type on admin screen.

Andrew Nacin wp at andrewnacin.com
Fri Jan 31 04:14:41 UTC 2014


On Thu, Jan 30, 2014 at 5:45 PM, Haluk Karamete <halukkaramete at gmail.com>wrote:

> on admin pages, how can I detect that the current admin is dealing with a
> cpt?
>
> dealing meas: he is about to "add new" or "edit" or "delete" a post that
> belongs to that cpt.
>
> something of this sort is what I'm looking for;
>
> if (is_admin() and get_post_type( $post ) == 'that_cpt')
>    bingo...


get_current_screen()->post_type. This will also specify a post type when
it's a taxonomy being edited. To filter that out ensure that
get_current_screen()->base === 'post', which is for edit.php, post-new.php,
and post.php (for all post types).


More information about the wp-hackers mailing list