1

I'm creating a product list with two custom taxonomies: the producer and the category. I've managed to display all of the producers and make the products display in a collapsible tab accordingly, but I want to exclude from display those producers, who don't have any products in the currently displayed category. The 'display all producers' code looks like this:

$terms = get_terms("producers");
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
                    $i=1;
                    foreach ( $terms as $term ) {
                    <div>producer's name, etc.</div>
                    }
                }

How do I exclude producers that don't have any products assigned in the CURRENT category? 'hide_empty' argument doesn't work, as they have products in other categories.

Edit: to be more clear, the category itself is shown basing on the current post, '/categories/trucks/' will show only trucks (but still all of producers, even those who do not have any trucks assigned)

0

1 Answer 1

1

All right, few hours of figuring it out, but I made it: I had to wrap the whole thing into a wp_query, querying the current 'category' term and then use get_the_terms instead of get_terms to get the terms for the current post query, then remove duplicates and echo it in a foreach loop similar to the initial one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.