Sorry for confusing title. Not sure how to describe it better. I'd like to display all shops first sorted by theirs categories, then, inside it, sorted by their locations.
I have custom post type "Shop", two custom taxonomies "Shop Category", "Shop Location".
Example how I'd like it to display:
Shoes
London
- Shop 01
- Shop 02
Tokyo
- Shop 05
- Shop 06
Electronics
London
- Shop 11
- Shop 12
Tokyo
- Shop 15
- Shop 16
Shoes, Electronics, (...) - Taxonomy #1
London, Tokyo, (...) - Taxonomy #2
Shop 01, (...) - Custom Post Type
Got it working to show sorted by one taxonomy so far. It works good but I need one more level.
<?php
$custom_terms = get_terms('shop_category');
foreach ($custom_terms as $custom_term) {
wp_reset_query();
$args = array(
'post_type' => 'shop',
'tax_query' => array(
array(
'taxonomy' => 'shop_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<div class="box-category">'.$custom_term->name.'</div>';
while($loop->have_posts()) : $loop->the_post();
echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>';
endwhile;
}
}
?>
Thanks in advance for directions.