Created
May 14, 2011 15:21
-
-
Save chriscoyier/972314 to your computer and use it in GitHub Desktop.
is_custom_post_type.php
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 | |
// returns boolean | |
function is_custom_post_type( $type = '' ) { | |
// access to currently queried post | |
global $post; | |
// get the current post type | |
$post_type = get_post_type( $post ); | |
// all post types that aren't custom | |
$types = array("post", "page", "revision", "attachment"); | |
// check if current post type is custom | |
if ( $type == '' && in_array($type, $types)) { | |
return true; | |
// if parameter passed, compare against that | |
} else if ( $type == $post_type ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is missing "nav_menu_item" as a default post type. Wouldn't it be easier to use the builtin argument in get_post_types() to create an array of all non-builtin post types? This would give you all custom post types (unless, of course, they were created as a builtin, but that would be bad practice). Then you wouldn't need the type argument, you could just use the array $types with your $post_type