Need customization on a taxonomy archive page

I am working on my local dev environment. I have a custom post type called: products. and a custom taxonomy called: product_cat.
I would like the taxonomy-product_cat.php to show:
1. First, show the product items belonging only to the current term and not of the parent or child term.
2. Then if the current term has child terms list out a list that will show the title of child term and its posts and then one more title and posts, if there is more than one child term.

  • Sohag Ronjon Dey

    Hi Talk,

    Thanks for contacting us and I hope that you are having a beautiful day. :slight_smile:

    This will require custom development. However you can try to add following to your custom taxonomy template. This will list all the child terms and their posts.

    $term_id = get_queried_object()->term_id;
    		$taxonomy_name =  get_queried_object()->taxonomy;
    		$term_children = get_term_children( $term_id, $taxonomy_name );
    		echo '<ul>';
    		foreach ( $term_children as $child ) {
    			$term = get_term_by( 'id', $child, $taxonomy_name );
    			$posts_array = get_posts(
    									'tax_query' => array(
    											'taxonomy' => $term->taxonomy,
    											'field' => 'slug',
    											'terms' => $term->slug
    			echo '<li>';
    			echo    '<a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a>';
    							echo '<ul>';
    								foreach ( $posts_array as $post ) : setup_postdata( $post );
    										echo '<li><a href="'.get_the_permalink().'">'.get_the_title().'</a></li>';
    							echo '</ul>';
    			echo '</li>';
    		echo '</ul>';

    Hope this helps.

    If you need any more functionality then I can only recommend advertising for a developer who might be able to custom develop this for you.

    Please keep in mind, developers found in our Jobs Section are not associated with us. So communicate with them well regarding your issue before you make any payments to them.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.