WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i'd like to list my 10 most recent posts but from certain categories only - anyone can tell me how to do this?


share|improve this question
up vote 6 down vote accepted

simply add this above your loop

$args = array(
    'posts_per_page' => 10,
    'category__in' => array( 2, 6 ), //change and add the category ids here
    'orderby' => 'date',
    'order' => 'ASC')

and you can read more about query_posts Parameters http://codex.wordpress.org/Function_Reference/WP_Query#Parameters


By popular demand :) here is another example to doing the same but using tax_query

$args = array(
    'tax_query' => array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => array('category1','category2') ////change and add the category slugs here
    'posts_per_page' => 10,
    'orderby' => 'date',
    'order' => 'ASC')
share|improve this answer
I'll give you a +1 if you update your answer to include an additional example of doing the same with tax_query using slugs .. ;) – t31os Mar 8 '11 at 12:31
@t31os - Only because you asked so nicely :) – Bainternet Mar 8 '11 at 13:21
Nice one, +1'ed!.. :) – t31os Mar 8 '11 at 13:34
10x for the "Popular demand" +1'ed too ;) – Sagive SEO Apr 2 '12 at 15:29

Have a look at the category query parameters here:


share|improve this answer

The easiest way to do this is to have use the category name in the query before the loop starts.

<?php query_posts($query_string . '&category_name='Your Category, Another Category'); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

I haven't tested it but should work.

Also check out http://codex.wordpress.org/Function_Reference/query_posts

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.