Created
July 15, 2010 13:55
-
-
Save mjangda/476964 to your computer and use it in GitHub Desktop.
Get the current post_type context in the WordPress admin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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