Determine if term is Category or Tag


I am working on a piece of code for my plugin and I am trying to find the best way to pull Terms in to post object. The object will have the usual title, description etc. but it will also need Categories and Tags. The issue I am facing is that if the post type is a custom post type with custom taxonomies (categories and tags), I can’t determine which is which.

$taxonomy_names = get_object_taxonomies(isset($post_type) ? $post_type : 'post');

$categories = '';

if(!empty($taxonomy_names)) {
   foreach($taxonomy_names as $taxonomy) {

       $category = wp_get_post_terms($id, $taxonomy, array(
            'fields' => 'all'


       $categories .= $category[0]->name . ',';


The above code prints out:

enter image description here

The top object is category and bottom is a tag – is there any way I could differentiate between these?

Fresz 1 month 0 Answers 8 views 0

Leave an answer