Custom post types do not use the standard categories or tags as normal posts, but the capability is there to create a custom taxonomy – a custom set of categories for a custom post type. However, the built-in WordPress function in_category() does not work with custom taxonomies. So, to figure out if a custom post is in a custom taxonomy, I added this function to my functions.php:
[php]// Query custom taxonomy category
function in_custom_category( $category, $_post = null ) {
if ( empty( $category ) )
return false;
if ( $_post ) {
$_post = get_post( $_post );
} else {
$_post =& $GLOBALS[‘post’];
}
if ( !$_post )
return false;
$r = is_object_in_term( $_post->ID, ‘CUSTOMCAT_SLUG’, $category );
if ( is_wp_error( $r ) )
return false;
return $r;
}[/php]
Replace the CUSTOMCAT_SLUG with the slug of your custom taxonomy (for example, movies-cat).
This returns a true if the post is inside the specified category. You can call this in an if statement such as,
[php]if (in_custom_category(‘drama’)){
// it is in the category – do something here
} else {
// not in the category, do something else
}[/php]