Grouping Custom Taxonomies based on Tags contained in Posts

[ad_1]

I have a custom taxonomy, and as navigation, on archive pages, I list all the children of a specific parent. I achieve it with this –

`<?php`

`$term_id = get_queried_object()->term_id;`

`$parent = get_queried_object()->parent;`

`$term = get_term($parent, ‘cars’ );`

`$args = array(`

`’orderby’ => ‘name’,`

`’order’ => ‘ASC’,`

`’hide_empty’ => true,`

`’child_of’ => $term->term_id,`

`’parent’ => $term->term_id,`

`);`

`$sub_terms = get_terms( ‘cars’, $args);`

`foreach ($sub_terms as $term) { ?>`

`<a type=”button” class=”btn btn-gcard me-2 mb-2″ href=”<?php echo get_term_link( $term ); ?>”><?php echo $term->name; ?></a>`

`<?php } ?>`

Now, every post within these custom taxonomies is also tagged (standard WordPress tags) either with “SUV” or “Coupe”, and my question is – could I somehow modify the above code to show only taxonomies that contain posts tagged with “SUV”?

So instead of having: Audi Cars (a6) (a8) (r8)
I would have something like : Audi SUVs (a6) (a8) Audi Coupes: (r8)

I know I can achieve this by adding another level of hierarchy to the taxonomy, but it’s too late for that.

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer