Skip to content

Instantly share code, notes, and snippets.

@VermillionOne
Created May 2, 2019 22:58
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 VermillionOne/0f05f71f63b60e5fc4a44ee21b505a56 to your computer and use it in GitHub Desktop.
Save VermillionOne/0f05f71f63b60e5fc4a44ee21b505a56 to your computer and use it in GitHub Desktop.
Check If Custom Post Type
/**
* Check if a post is a custom post type.
* @param mixed $post Post object or ID
* @return boolean
*/
function is_custom_post_type( $post = NULL )
{
$all_custom_post_types = get_post_types( array ( '_builtin' => FALSE ) );
// there are no custom post types
if ( empty ( $all_custom_post_types ) )
return FALSE;
$custom_types = array_keys( $all_custom_post_types );
$current_post_type = get_post_type( $post );
// could not detect current type
if ( ! $current_post_type )
return FALSE;
return in_array( $current_post_type, $custom_types );
}
if ( is_custom_post_type() )
print 'This is a custom post type!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment