Query posts that match two tags (3 posts)

  1. chrisrahe
    Posted 4 years ago #

    First of all, I'm very much a novice.

    I'm trying to create a page that will list posts, but break them into different categories. The page will change each month.

    So I have a bunch of posts for October, but some of them are in category 1, some category 2, and so on.

    I've created posts and they're all tagged with "October 2011" but some of them have a second tag of "Section 1" and some of "Section 2".

    So on the WordPress page I want the first section to show the posts that have both "October 2011" and "Section 1" for tags - excluding anything with "September 2011" or "Section 2", etc.

    Does that make sense?

    The Query I currently have is:

    <?php query_posts("posts_per_page=20&tag=october-2011"); ?>

    That pulls up everything for October, but how can I make it pull up only posts with the "October 2011" tag that also have the "Section 1" tag?

  2. Michael
    Forum Moderator
    Posted 4 years ago #



    <?php query_posts(array('posts_per_page' => 20, 'tag_slug__and' => array('october-2011', 'section-1'))); ?>
  3. chrisrahe
    Posted 4 years ago #

    Perfect! Thanks so much.

Topic Closed

This topic has been closed to new replies.

About this Topic