query recent posts from several categories

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

thanks

Related posts

Leave a Reply

3 comments

  1. 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')
    query_posts($args);
    

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

    Update

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

    $args = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => array('category1','category2') ////change and add the category slugs here
            )
        )
        'posts_per_page' => 10,
        'orderby' => 'date',
        'order' => 'ASC')
    query_posts($args);