Hi I am trying to display the child term of the current post category page. However I can figure out what am missing here. Thanks
<?php $current_tax = get_query_var( 'category' ); $current_term = get_queried_object()->term_id; $child_terms = get_terms( array('category' => $current_tax, 'child_of' => $current_term, 'orderby' => 'name' )); if ( ! empty( $child_terms ) && ! is_wp_error( $child_terms ) ) { echo '<div class="post-index__cate">'; foreach( $child_terms as $child ) { printf( '<a class="category-name" href="%s">', get_term_link( $child, $child->taxonomy )); echo $child->name. '</a>'; } echo '</div>'; } ?>
Advertisement
Answer
In your code the taxonomy should be “category”, so your arguments for get_terms() should have “taxonomy” => “category”. $current_tax is irrelevant in this code then.