X

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:

Code Snippet:

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;
}
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!