Display all subterms of a custom taxonomy filtered by parent terms
Question
I have a custom taxonomy which i called ‘fonte’ that should display a list of books. These are divided in two parent terms, ‘mixed’ or ‘single’. So the hierarchy is something like that:
Mixed
- book1
- book2
- book3 …
Single
- book4
- book5
- book6
I’d like the page template to show the two parent terms ‘mixed’ and ‘single’ as selectable filters, so that when I click on one of them they display their child terms, but I believe I’m not able to do this.
What I have so far:
<?php
$terms = get_terms( 'fonte' );
;
foreach ( $terms as $term ) {
if ($term->parent != 0){
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
echo ' <div class="element">
<div class="pf-body c27-content-wrapper"><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a> </div>
</div>';
echo $term->description; // This will return the description of the term
}
}
;
?>
0
1 month
0 Answers
7 views
0
Leave an answer
You must login or register to add a new answer .