Discussion:
identifying the current post type on admin screen.
Haluk Karamete
2014-01-30 22:45:12 UTC
Permalink
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...

which obviously would not work.
Morgan Estes
2014-01-31 04:07:50 UTC
Permalink
There are a couple of ways to get the post type of the page being edited.
Here's one works for me:

add_filter( 'admin_head', 'get_cpt_page' );

function get_cpt_page() {
if ( 'that_cpt' == get_post_type() ) {
// do cool stuff here
}
}

Morgan W. Estes
about.me/morganestes
Post by Haluk Karamete
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...
which obviously would not work.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Andrew Nacin
2014-01-31 04:14:41 UTC
Permalink
Post by Haluk Karamete
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).
Frank Bueltge
2014-01-31 05:49:52 UTC
Permalink
Use the function get_current_screen to identifier the current page,
including post type.
You can use the plugin Debug Objects to see all data of get_current_screen
to easier understand the benefit.

Best Frank
Post by Andrew Nacin
Post by Haluk Karamete
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).
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Haluk Karamete
2014-01-31 05:58:30 UTC
Permalink
Thank you all.
Post by Frank Bueltge
Use the function get_current_screen to identifier the current page,
including post type.
You can use the plugin Debug Objects to see all data of get_current_screen
to easier understand the benefit.
Best Frank
Post by Andrew Nacin
Post by Haluk Karamete
on admin pages, how can I detect that the current admin is dealing
with a
Post by Andrew Nacin
Post by Haluk Karamete
cpt?
dealing meas: he is about to "add new" or "edit" or "delete" a post
that
Post by Andrew Nacin
Post by Haluk Karamete
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,
Post by Andrew Nacin
and post.php (for all post types).
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Continue reading on narkive:
Loading...