Check If Post In Custom Taxonomy
Filed Under (Light Reading, Wordpress Tips) by Wpfeed on 29-12-2011
Custom taxonomies is a great tool, you can create by yourself more ways to categorized posts or custom posts and in that way use wordpress as much better and advanced CMS.
suprisingley there isn’t yet a function to use if you want to check if a post is attached to a custom taxonomy (unless you check it with a single term of that given taxonomy – like in this example – http://wordpress.org/support/topic/custom-taxonomies-conditional-tags?replies=13#post-1110167)
let’s say you created a custom taxonomy called “video”, and you want to display different border to the featured image in the LOOP or any other icon near this post to show that it is a video.
you can use this function which returns the list of objects of a given taxonomy:
$video_terms = wp_get_object_terms($post->ID, ‘video’);
if(!empty($video_terms)){
if(!is_wp_error( $video_terms )){
//show your icon or any other sign of this taxonomy
}
}
Popularity: 1% [?]












