Custom taxonomy conditional tag

Conditional tags are a useful tool for those who want interactive and more awesome themes. They let you place if-statements and do stuff if certain conditions are true.

Since WordPress 3.0 you can add your own taxonomies, but unfortunately, there are no conditional tags for it, so you’ll have to add your own.

How to use:

if ( has_person( 'tom-cruise' ) ) {<br />
/* do something */<br />
};

Code Snippet:

<?php
function has_person( $person, $_post = null ) {
	if ( empty( $person ) )
		return false;
	if ( $_post )
		$_post = get_post( $_post );
	else
		$_post =& $GLOBALS&#91;'post'&#93;;
	if ( !$_post )
		return false;
	$r = is_object_in_term( $_post->ID, 'person', $person );
	if ( is_wp_error( $r ) )
		return false;
	return $r;
}
?>

Posted in Conditional