Wordpress - How do i know the current post type when on post.php in admin?
add_action( 'admin_init', 'do_something_152677' );
function do_something_152677 () {
// Global object containing current admin page
global $pagenow;
// If current page is post.php and post isset than query for its post type
// if the post type is 'event' do something
if ( 'post.php' === $pagenow && isset($_GET['post']) && 'post' === get_post_type( $_GET['post'] ) )
// Do something
}
}
I am going to expand on MiCc83's answer. There are a few things that don't follow the OP's original questions but overall it's a great solution. For example, it would not work with a post_type event because you are checking the post_type as 'post' in the answer.
add_action( 'admin_init', 'do_something_152677' );
function do_something_152677 () {
// Global object containing current admin page
global $pagenow;
// If current page is post.php and post isset than query for its post type
if ( 'post.php' === $pagenow && isset($_GET['post']) ){
$post_id = $_GET['post'];
// Do something with $post_id. For example, you can get the full post object:
$post = get_post($post_id);
}
}
The condition 'post' === get_post_type( $_GET['post'] )
in the previous answer would prevent this from working on a post type 'event'. You would need to check for post type 'event' instead of 'post'.