Check If Post In Custom Taxonomy

By -

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

WordPress is a full featured Content Management System (CMS). It has incorporated a rich suite of capabilities that have proven to be extremely popular because it allows anyone to create vibrant, dynamic sites without any programming knowledge. Its large range of features, coupled with a clean and easy-to-understand interface make it a fan fave among website novices; 27% of all the websites in existence and 20% of all new ones use this amazing platform.

Leave a Reply

Your email address will not be published. Required fields are marked *

Human test: *