Support » Fixing WordPress » Query posts that match two tags
5 years, 3 months 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?
<?php query_posts(array('posts_per_page' => 20, 'tag_slug__and' => array('october-2011', 'section-1'))); ?>
Perfect! Thanks so much.