Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created July 15, 2010 13:55
Show Gist options
  • Save mjangda/476964 to your computer and use it in GitHub Desktop.
Save mjangda/476964 to your computer and use it in GitHub Desktop.
Get the current post_type context in the WordPress admin.
<?php
/**
* Gets the current global post type if one is set
*/
function x_get_current_post_type() {
global $post, $typenow, $current_screen;
if( $post && $post->post_type )
$post_type = $post->post_type;
elseif( $typenow )
$post_type = $typenow;
elseif( $current_screen && $current_screen->post_type )
$post_type = $current_screen->post_type;
elseif( isset( $_REQUEST['post_type'] ) )
$post_type = sanitize_key( $_REQUEST['post_type'] );
else
$post_type = null;
return $post_type;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment