How to list custom taxonomy 1 terms related to current taxonomy 2 term
-
Hey,
I have a custom post type “Products” that have two Taxonomy: “Categories” and “Counties”.
My problem is:
When I visit a Categories Term page that have children, I want to list name of all Counties terms related to current Categories term and his children.I have this code that list me all Counties terms related only to current term, not and his children.
$taxomnomy = get_queried_object(); $cat = $taxomnomy->term_taxonomy_id; // current categories term id $taxonomy = 'counties'; $sql = " SELECT DISTINCT t2.name FROM $wpdb->terms t2 JOIN $wpdb->term_taxonomy tt2 ON (t2.term_id = tt2.term_id AND tt2.taxonomy = '$taxonomy') JOIN $wpdb->term_relationships tr2 ON (tt2.term_taxonomy_id = tr2.term_taxonomy_id) JOIN $wpdb->posts p ON tr2.object_id = p.ID JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id AND tr.term_taxonomy_id = $cat) ORDER BY t2.name ASC "; // print_r("<p>SQL:$sql</p>"); $values = $wpdb->get_col($sql); // print_r($values); foreach ( $values as $term ) { echo 'County: '.$term; }
Thanks.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to list custom taxonomy 1 terms related to current taxonomy 2 term’ is closed to new replies.