taxonomy – Group custom taxonomies based on tags contained in their posts


I have a piece of code that shows links to children of a parent taxonomy on archive pages. My goal however is to separate these children into groups, based on the tags (standard WordPress tags).

My custom taxonomy is “Graphic Cards”, and it has two parents “NVidia” and “AMD”, and each has a bunch of children.

Right now the code below shows either all children of NVidia or all children of AMD, but I wanna be able to separate both NVidia and AMD into tags. Each post containing these graphic cards is also tagged with tags “desktop GPU” or “notebook GPU”.


                $term_id = get_queried_object()->term_id;
                $parent = get_queried_object()->parent; 
                $term = get_term($parent, 'graphic-cards' );
                $args = array(
                    'orderby' => 'name', 
                    'order' => 'ASC',
                    'hide_empty' => true,
                    'child_of' => $term->term_id,
                    'parent' => $term->term_id,
                $sub_terms = get_terms( 'graphic-cards', $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 } ?>

So Instead of getting AMD Gpus – 5600, 6600m, 7600

I want to be getting – AMD Gpus (Desktop) 5600,7600 (Notebook) 6600m

Is this achievable, or I’m thinking wrong about it?

Dan 1 year 2022-11-12T12:04:52-05:00 0 Answers 0 views 0

Leave an answer