WordPress.org

Ready to get started?Download WordPress

Forums

multiple query_posts into one "AND" (6 posts)

  1. JonasVorwerk
    Member
    Posted 2 years ago #

    I would like to know how to merge several queries into one. Now I do several query_post but I should be possible with just one.

    For example:

    (show a certain post)

    $args = array(
    	'p' => 3
    )

    AND

    (show the latest 25 posts)

    $args = array(
    	'showposts' => 25
    );

    AND

    (show posts in categories at all times)

    $args = array(
    	'category__in' => array(6,7,41)
    );

    Thanks in advance

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Based on what you've posted above:

    $args = array(
    	'p' => 3,
    	'posts_per_page' => 25,
    	'category__in' => array(6,7,41)
    );

    but that wont work as you're asking for both a single post AND 25 posts.

  3. JonasVorwerk
    Member
    Posted 2 years ago #

    That's not what I'm searching for.
    The result I'm looking for is 25 last posts + all the posts form certain categories

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    You'll need 2 queries for that - 1 for the 25 latest posts and the second for all the posts from certain categories. You might want to have a look at multiple Loops for some examples.

  5. JonasVorwerk
    Member
    Posted 2 years ago #

    This means duplicate posts which we don't want..
    Thanks again!

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    Not necessarily. You could loop through the objects returned from each query and weed out any duplicates before outputting the results to any page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.