List All Terms With Posts in A Specific Category

Question

The following code lists all terms in a taxonomy, specifically all possible values of an attribute in my WooCommerce store:

<ul>
    <?php
    $taxonomies = array( 'pa_diameter' );
    $args = array( 'hide_empty' => 0 );
    $terms = get_terms( $taxonomies, $args );
    $empty_terms = array();
    foreach( $terms as $term ){
        echo '<li>' . $term->name . '</li>';
    }
    ?>
</ul>

However I only want to display the values if posts/products that have them are also in a specific category, i.e. product_cat = 'sample-cat'. How would I do that?

0
onesixty 2 months 0 Answers 12 views 0

Leave an answer