Viewing 3 replies - 1 through 3 (of 3 total)
  • Here’s some sample code from Austin Matzko (filosofo), to get 5 posts in 6 different categories, that you might like:

    $post_ids = array(0);
    foreach( array(1, 2, 3, 4, 5, 6) as $cat_id ) {
            if ( $posts = get_posts(array('cat' => $cat_id, 'showposts' => 5)) ) {
                    $first = array_shift($posts);
                    $post_ids[] = $first->ID;
            }
    }
    query_posts(array('post__in' => $post_ids));

    Thread Starter Alkorr

    (@alkorr)

    Thank you Michael! So with this code I only make 1 query and not 4 like with my previous code, right?

    And what about the tags? I looked at the Codex and it’s not very clear to me…

    🙂

    Guess you could try the tag__in argument in that get_posts code.

    Thequery_posts() article has info on tag__in but I believe you can use that argument with get_posts

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Multiple Showpost Queries’ is closed to new replies.