I am trying to pull a list of custom taxonomies from a CT of business-types
. I am looping round them like so:
<?php $terms = get_terms("business-types");
foreach ( $terms as $term ) { ?>
<div>
<img src="<?php the_field('category-image', $term); ?>" alt="" />
<a href="<?php echo esc_url( get_term_link( $term ) ) ?>"><?php echo $term->name; ?></a>
</div>
<?php } ?>
This works and is listing the name with a link, and an image as assigned in the backend with ACF. Now, one of these taxonomies has children, so the idea is that if you click one with children, you're then shown the sub-children of that business-type. This doesn't work, it just lists all of them. Here's an example of the CT layout:
- Professional
- Retail
- Hospitality
- Restaurants
- Coffee Shops
- Takeaway
So basically, you click businesses and it shows you professional
, retail
and hospitality
. You click hospitality
and the same template is used to show restaurants
, coffee shops
and takeaway
. Then you click one of those and it lists all posts (In a CPT) with that term.
Currently, you click hospitality
and it just lists everything under that... Any ideas on how I can do this multi-level in the same template?
edit: it seems to be outputting all terms which have posts assigned to them... Even the children items. I also need to know how to show only top level items for the term you're in...
Cheers, Ash