I have a list of products that site under product categories that work well. I also have CPT setup of ‘shop_location’ so here we can list different shop locations.
I want to show the product categories (that have products) for a specfic taxonomy of shop_location.
So e.g. I want to show all product categories (with products), for the shop_location which is equals to London.
I have tried the following but this is not firing correctly, could someone please help me. Thank you!
<?php
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'tax_query' => array(
array(
'taxonomy' => 'shop_location',
'terms' => array( $category->slug ),
'field' => 'london',
)
)
);
$product_categories = get_terms( 'product_cat', $cat_args );
if( !empty($product_categories) ){
echo '
<ul>';
foreach ($product_categories as $key => $category) {
echo '
<li>';
echo '<a href="'.get_term_link($category).'" >';
echo $category->name;
echo '</a>';
echo '</li>';
}
echo '</ul>
';
}
?>