Created
October 27, 2011 17:18
-
-
Save ninnypants/1320182 to your computer and use it in GitHub Desktop.
Test if a post is in a specific taxonomy
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 | |
/* | |
** $taxonomy = Taxonomies to retrieve terms from | |
** $tax = Term slug or id to test against | |
*/ | |
function in_tax($taxonomy, $tax){ | |
global $post; | |
$taxes = array(); | |
if(is_int($tax)){ | |
$terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); | |
}else{ | |
$terms = wp_get_object_terms($post->ID, $taxonomy); | |
foreach($terms as $term){ | |
$taxes[] = $term->slug; | |
} | |
$terms = $taxes; | |
} | |
return in_array($tax, $terms); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment