Retrieve post of child category
-
Hello,
I want to retrieve post of a child category, by it’s parent category?
What I mean?
Let’s say I have a subcategory name dogs, and it’s parent name animals.
What I want is to retrieve the posts of dogs category, and it’s need to be parent category-depended.
I saw this code on the web, it help a bit, but it retrieve all posts of all childs, and I want only of a specific child category.
This is the code:<?php //get all posts for children of category $cata $cata = $cat_id; $taxonomy = 'category'; $cata_children = get_term_children( $cata, $taxonomy ); $args=array( 'category__in' => $cata_children, ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo 'List of Posts belonging to Category A children'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Any help? Thanks!
- The topic ‘Retrieve post of child category’ is closed to new replies.