WordPress.org

Ready to get started?Download WordPress

Forums

Specifying more than one category condition for get_posts (4 posts)

  1. marc0047
    Member
    Posted 8 years ago #

    I would like to generate a list of posts if they exist in two categories.

    Is it possible to do something like this?


    <?php
    $posts = get_posts('category=1&category=2');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>

  2. intricateartist
    Member
    Posted 7 years ago #

    Any answer on this one yet? I'm looking to do the same thing.

  3. intricateartist
    Member
    Posted 7 years ago #

    (the suggested code above does not work)

  4. Kafkaesqui

    Posted 7 years ago #

    Your answer:

    http://codex.wordpress.org/Template_Tags/query_posts
    http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

    Note that if you're planning to use this in a template which will have one or more other post loops (including The Loop), creating a new WP_Query class would be better suited for it:

    http://wordpress.org/support/topic/35262#post-200765

Topic Closed

This topic has been closed to new replies.

About this Topic