I have a custom post type ‘downloads’ which i have a have a custom template set up to get terms of to begin with. Im now trying to set up my taxonomy template so that it displays sub-categories if there are any, but if not to show posts for that term.

Below is what my taxonomy template includes so far and this works fine to the point that it displays the child categories, but it doesnt then show the posts for that category at the end. Id like it so that if there are child categories then show them, else show the posts for that category.

                $term = get_queried_object();
                $term_id = $term->term_id;
                $taxonomy_name = $term->taxonomy;

                $termchildren = get_term_children( $term_id, $taxonomy_name );?>

                        <?php foreach ( $termchildren as $child ) {
                        $term = get_term_by( 'id', $child, $taxonomy_name ); ?>
                              <?php echo $term->name; ?>
                              <?php echo $term->description; ?>
<?php } ?>

Read more here: Displaying subcategories and then posts in taxonomy template


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: