List All Terms With Posts in A Specific Category


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

    $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>';

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?

onesixty 2 months 0 Answers 12 views 0

Leave an answer