0

The following code is inserted in a the taxonomy brand page and it shows all product_cats for a specific brand.

<?php 
                $argsproduct = array(
                    'post_type' => 'product',
                    'posts_per_page' => -1,
                    'tax_query' => array( 
                        'relation' => 'AND',
                        array(
                            'taxonomy' => 'product_brand', 
                            'field' => 'term_id', 
                            'terms' => $term_id
                        ) 
                    ),  
                );
                $porductposts = get_posts( $argsproduct );

                $outprocatslug = array();
                $outprocatname = array();               
                $outprocatid = array();

                foreach ( $porductposts as $porductpost ) {
                    $terms = get_the_terms( $porductpost->ID, 'product_cat');

                    if ( $terms && ! is_wp_error( $terms ) ) {
                        foreach ( $terms as $term ){
                            $outprocatid[] = $term->term_id;
                            $outprocatslug[] = $term->slug;
                            $outprocatname[] = $term->name;
                        }
                    }
                }   

                $termini = get_terms( array(
                    'taxonomy' => 'product_cat',
                    'include'  => $outprocatid,
                ) );
                foreach ($termini as $termine){
                    echo '<p><a class="" href="' .get_term_link($termine->slug, 'product_cat') .'?bvbrand='.$term_slug.'">'.$termine->name.'</a></p>';
                }



                /////} foreach $porductposts

                ?>

It only shows the child category, but not the parent category. Can someone help me to understand how to integrate it to show also the parent category? Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.