jmccole83
3/8/2019 - 11:18 AM

Get Child Categories (posts, products, events, etc)

@php
  $taxonomy_name = get_queried_object()->taxonomy; // Get the name of the taxonomy
  $term_id = get_queried_object_id(); // Get the id of the taxonomy
  $termchildren = get_term_children( $term_id, $taxonomy_name ); // Get the children of said taxonomy
@endphp

<div class="sub-categories">
  <ul class="child-cats">
  @foreach ( $termchildren as $child )
    @php $term = get_term_by( 'id', $child, $taxonomy_name );
    echo '<li><a href="' . get_term_link( $term->name, $taxonomy_name ) . '">' . $term->name . '</a></li>'; @endphp
  @endforeach
  </ul>
</div>