Get Unique WordPress Post In Parent Category

I have a parent category and several child categories. I also have several posts that belong to the child categories. Each post can be belong to several categories. I want to know how to query the post table so when I want to show all posts in parent category, I’ll get all the post under the child categories. the result have to unique post.

The WordPress query should be able to handle it. Whether you’re using the query_posts or your own instance of WP_Query, simply pass the arguments. see following example

<?php 
$args = array (
  'cat' -> 1, // Category ID of Parent Category (in this case, 1)
  'posts_per_page' -> 10 // Show 10 posts from this category, set to -1 to show all
);
query_posts($args); 
if ( have_posts() ) : while ( have_posts() ) : the_post(); 
?>
  <!-- Do something -->
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments