Support » Themes and Templates » Help with wp_query

  • Hello,

    I have been reading and researching and sadly, I fear my answer is so simple that people are like “Eh, everyone knows THAT!” and the answer cannot be find by me.

    Here is the code:

    <?php $my_query = new WP_Query('orderby=rand'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post();?>

    And what I want to query specific categories, the last number of posts in those categories, for example:

    scrolling in order, the last 2 posts from categories 2,4,7,22,100

    Can someone help me know what to write in there?

Viewing 1 replies (of 1 total)
  • Austin Matzko (filosofo) showed this, I believe on the wp-hackers list:

    $post_ids = array(0);
    foreach( array(2, 4, 7, 22, 100) as $cat_id ) {
            if ( $posts = get_posts(array('cat' => $cat_id, 'showposts' => 2)) ) {
                    $first = array_shift($posts);
                    $post_ids[] = $first->ID;
    query_posts(array('post__in' => $post_ids));
    //your loop here

Viewing 1 replies (of 1 total)
  • The topic ‘Help with wp_query’ is closed to new replies.