WordPress.org

Forums

[resolved] Multiple continuous WP_Queries? (6 posts)

  1. roniel
    Member
    Posted 2 years ago #

    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?

  2. catacaustic
    very awesome
    Posted 2 years ago #

    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.

  3. roniel
    Member
    Posted 2 years ago #

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

  4. catacaustic
    very awesome
    Posted 2 years ago #

    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.

  5. roniel
    Member
    Posted 2 years ago #

    Yeah the offset argument works! Thank you so much!

  6. catacaustic
    very awesome
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic