The title sounds complex but this is quite simple. Hopefully the code for it is too. I have this custom taxonomy we'll call "Filters".
- ParentTerm A
- ChildTerm 1A
- ChildTerm 2A
- Parent Term B
- Child Term 1B
- Child Term 2B
On a page that has a listing of custom post types, I was easily able to display all the terms selected for the "Filters" taxonomy by putting this in my loop/query:
<?php
$terms = get_the_terms( $post->ID, 'filters' );
if ( $terms && ! is_wp_error( $terms ) ) :
$listing_filters = array();
foreach ( $terms as $term ) {
$listing_filters[] = $term->name;
}
$listing_filters = join( ", ", $listing_filters );
?>
<p class="listing-filters"><?php echo $listing_filters; ?></p>
<?php endif; ?>
The PROBLEM is for this page I only want to display the terms selected under ParentTerm A.
So ChildTerm 1A and ChildTerm 2A would display if they were checked off. But no other terms would display, not ParentTerm A, nor of course any terms in Parent Term B.
However as noted with the above code I of course get any and all selected terms for this custom taxonomy. Any ideas? Thanks!!