Skip to content

Instantly share code, notes, and snippets.

@pelmered
Forked from mjangda/get_current_post_type.php
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelmered/e8844753a4bd83832224 to your computer and use it in GitHub Desktop.
Save pelmered/e8844753a4bd83832224 to your computer and use it in GitHub Desktop.
<?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