How to show list of child taxonomy with post archive wordpress

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

How to show list of child taxonomy with post archive wordpress

How to show list of child taxonomy with post archive wordpress

How to show list of child taxonomy with post archive wordpress

Here I wrote the article about to show list of child taxonomy with post archive wordpress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php 
$term = get_queried_object();
 
//Get all children of this term;
$children = get_terms( 'fruit', array('parent'=>$term->term_id) ) ;
 
if($children):
    //We have an array of child (of current genre) terms. Loop through and display the posts
    foreach($children as $child):
        echo '<dt>'.$child->slug.'</dt>';
 
        // The Query - get all posts for this child-genre.
        $args = array('post_type' => 'recipe', 'taxonomy' => 'fruit', 'term' => $child->slug, 'post_status' => 'publish','posts_per_page' => -1);
        $child_posts = new WP_Query ($args);
        // The Loop - display all posts for this child-genre.?>
        <li><?php the_title();</li>
        <?php  endwhile;?>
       <?php  // Reset Post Data
 
    endforeach;
 
endif;
?>

Add comment


 

Pin It on Pinterest

Share This