Display all subterms of a custom taxonomy filtered by parent terms


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:


  • book1
  • book2
  • book3 …


  • 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:

      $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 ) ) {

      // 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>
      echo  $term->description; // This will return the description of the term



Marco Vez 8 months 2020-12-07T12:10:20-05:00 0 Answers 7 views 0

Leave an answer