How to get categories where term taxonomy is ‘my_custom_value’
-
get_the_category fetches categories from term_taxonomy where taxonomy value is ‘category’. But I want to get the categories from term_taxonomy where the taxonomy value is ‘my_custom_value’ instead of ‘category’. Can I modify get_the_category to fetch array from term_taxonomy where taxonomy is ‘my_custom_value’, or do I need to create a custom query? If a query is the only way, please advise on the best way.
For the query…this is what I have so far. It works, but does not filter out the terms related to other posts. I can’t figure out how to tell the query, “only show me the terms where the posts.ID matches the $post->ID”. What do I need to add to this to only get terms related to the post being viewed? Thanks in advance for your help!
$termquery= $wpdb->get_results (" SELECT $wpdb->terms.name FROM $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id WHERE $wpdb->term_taxonomy.taxonomy = 'my_custom_value' ORDER BY name ASC "); $displayterms = $wpdb->get_col($termquery['name']); echo json_encode($displayterms);
- The topic ‘How to get categories where term taxonomy is ‘my_custom_value’’ is closed to new replies.