I have a custom taxonomy with a slug “colour”. And I have normal tags. I use them both on posts.
So I want to create a page that displays a tag cloud listing all taxonomy terms that are associated in any post with tag “large”, for example.
Example:
* Post 1 —- Taxonomy slug: colour —- Taxonomy term: Black —- Tag: Large
* Post 2 —- Taxonomy slug: colour —- Taxonomy term: White —- Tag: Large
* Post 3 —- Taxonomy slug: colour —- Taxonomy term: White —- Tag: Small
* Post 4 —- Taxonomy slug: colour —- Taxonomy term: Red —- Tag: Medium
* Unrelated Page —- Tag cloud output for tag Large: Black, White
I managed to get the desired result with the bellow query, but I’m really having trouble to turn that into wp php code. The idea of the sql were to first list all posts that have that specific tag Latge (term\_taxonomy\_id=102). Then I got all the object\_id from these posts and listed the terms for the desired taxonomy (term slug = taxonomy-slug).
But I don’t have a clue how to translate this to the code.
SELECT wp.post_title,
wtt.taxonomy,
wt.slug
FROM wp_posts wp,
wp_term_relationships wtr,
wp_term_taxonomy wtt,
wp_terms wt,
(SELECT wtr.object_id as ID FROM wp_term_relationships wtr WHERE wtr.term_taxonomy_id = 102) AS wtr_thc
WHERE wp.ID = wtr_thc.ID
AND wtr.object_id = wp.ID
AND wtt.term_taxonomy_id = wtr.term_taxonomy_id
AND wtt.taxonomy = ‘taxonomy-slug’
AND wt.term_id = wtt.term_id
​
[ad_2]