WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Multiple continuous WP_Queries?

[Resolved] Multiple continuous WP_Queries?

  • Is there a way to have WP_Query take in arguments that would allow you to query the latest 4 posts, for example, in one div and then the next 4 in another div?

    I need this behavior for a slider. If not, what are some alternatives?

Viewing 5 replies - 1 through 5 (of 5 total)
  • catacaustic
    very awesome

    @catacaustic

    I wouldn’t use WP_Query as that will over-write the query for the current page/post/etc.

    Instead I’d use the get_posts() function and query the database directly using that.

    Fair enough. What arguments would you give get_posts() if you wanted posts 1-4 in one div and posts 5-8 in another?

    catacaustic
    very awesome

    @catacaustic

    Something like this…

    $col_1 = get_posts (array (
        "numberposts" => 4,
        "orderby" => "post_date",
        "order" => "DESC"
    ));
    
    $col_2 = get_posts (array (
        "numberposts" => 4,
        "offset" => 4,
        "orderby" => "post_date",
        "order" => "DESC"
    ));

    That’s not etested, so you might have to play around with the settings a bit.

    Yeah the offset argument works! Thank you so much!

    catacaustic
    very awesome

    @catacaustic

    This is when I should mention that you really should take the time to look through the codes page that I linked to before, and that way you’ll be able ot see what this function can do for yourself. The codex is a great source of info, and can easily answer questions like this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Multiple continuous WP_Queries?’ is closed to new replies.