specific custom taxonomy terms by category id
-
This is an offshoot of another thread here: https://www.ads-software.com/support/topic/276635/page/2?replies=39
I am trying to get the terms of a custom taxonomy called ‘media’ by a category. I have been toiling over this and just returned my code back to the way it was. I don’t see why this is not working but it seems to me that terms within a custom taxonomy either do not have the term_link term_name and term_id tables or that they will not be returned using the get_tag_link function.
This is probably the deepest I have ventured into sql queries so any help is much aprpeciated. Here is the function followed by my template code. please note that my tables do not use the default wp_ prefix.
function get_category_media($args) { global $wpdb; $tags = $wpdb->get_results (" SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link FROM dorightby_posts as p1 LEFT JOIN dorightby_term_relationships as r1 ON p1.ID = r1.object_ID LEFT JOIN dorightby_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id LEFT JOIN dorightby_terms as terms1 ON t1.term_id = terms1.term_id, dorightby_posts as p2 LEFT JOIN dorightby_term_relationships as r2 ON p2.ID = r2.object_ID LEFT JOIN dorightby_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id LEFT JOIN dorightby_terms as terms2 ON t2.term_id = terms2.term_id WHERE t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND t2.taxonomy = 'media' AND p2.post_status = 'publish' AND p1.ID = p2.ID ORDER by tag_name "); $count = 0; foreach ($tags as $tag) { $tags[$count]->tag_link = get_tag_link($tag->tag_id); $count++; } return $tags; }
<?php $mediaargs = array( 'categories' => '30' ); $tags = get_category_media($mediaargs); foreach ($tags as $tag) { $content = "<a href=\"$tag->term_link\">$tag->term_name</a>"; } echo $content; ?>
- The topic ‘specific custom taxonomy terms by category id’ is closed to new replies.