Codesnipp.it Social Code Sharing

Amber Weinberg

Conditional Function For Checking If Post Is In Custom Taxonomy

by Amber Weinberg on Oct 25, 2011

<?php // Taken from http://wordpress.org/support/topic/custom-taxonomies-conditional-tags ?> <?php // in functions.php ?> <?php function has_person( $person, $_post = null ) { if ( empty( $person ) ) return false; if ( $_post ) $_post = get_post( $_post ); else $_post =& $GLOBALS['post']; if ( !$_post ) return false; $r = is_object_in_term( $_post->ID, 'NAME-OF-TAXONOMY', $person ); if ( is_wp_error( $r ) ) return false; return $r; } ?> <?php // where you want to display the conditional ?> <?php if ( has_person( 'NAME-OF-CATEGORY' ) ){ ?>TEST<?php } ?>

Can't see the comments? Please login first :)