Taxonomy Intersections and Unions
October 1, 2007
WordPress 2.3 has built-in support for some common and useful tag and category queries. A public query variable named “tag” allows retrieving all posts associated with one or more tags. Here are some examples.
- tag=wordpress-23 fetches all posts on this blog with the “WordPress 2.3″ tag.
- tag=wordpress-23,wordpress-24 fetches posts with either the “WordPress 2.3″ or the “WordPress 2.4″ tag.
- tag=wordpress-23+wordpress-24 fetches posts with both the “WordPress 2.3″ and the “WordPress 2.4″ tag.
There are also a number of private query variables that plugins can use to perform union and intersection queries for categories and tags. Plugins can insert these queries into the global query by hooking onto the ‘parse_request’ action and calling $wp->set_query_var() from their handler.
- category__in – Accepts an array of category IDs. Fetches posts in any one of the specified categories.
- category__not_in – Accepts an array of category IDs. Fetches posts that are not in any of the specified categories.
- category__and – Accepts an array of category IDs. Fetches posts that are in all of the specified categories.
- tag__in – Accepts an array of tag IDs. Fetches posts having any one of the specified tags.
- tag__not_in – Accepts an array of tag IDs. Fetches posts that do not have any of the specified tags.
- tag__and – Accepts an array of tag IDs. Fetches posts that have all of the specified tags.
- tag_slug__in – Accepts an array of tag slugs. Fetches posts having any one of the specified tags.
- tag_slug__and – Accepts an array of tag slugs. Fetches posts that have all of the specified tags.
20 Comments
Trackbacks
- 你可能不知道的 WordPress Taxonomy 新功能 ¶ Lvx ex Cælis
- 你可能不知道的 WordPress Taxonomy 新功能 ¶ Lvx ex Cælis
- Ryan Boren on Tags and the Loop | Bloggercamp
- WordPress weekly digest 1st October to 7th October 2007 « westi on wordpress
- Famous last words of Marius » IBM Patent, RWC and RSS feed update - 13 October 2007
- Ad-hoc article return using WP2.3’s tagging system : Kick ass! | The Wholesale Monkey Farm V2.0
- links for 2007-10-19 | Ge Xiaofei
- WordPress 2.3.1 in detail « westi on wordpress
- My First Wordpress 2.3 Update Notification and Subversion Upgrade
- QUiXO BlOG » Nuovo aggiornamnto per Wordpress.
- WordPress 2.3.1 | DevStorming.com
- Antonio Trigiani w3bL0g - Informatica Virale » Blog Archive » Aggiornamenti Wordpress 2.3.1 security fix
- Metric Tensor / links for 2007-11-14
- Sonika’s blog » Немного о таксономии и тегах в WordPress
- Categories and Tags - Search and Sort « Feet up, eyes closed, head back
Comments are closed.
Thanks for this post Ryan.
can you also post how we can make the home page to show only posts from certain tags.?
I would very much like to see a code sample that can be added before the call to the_loop, that helps in doing this.
Thanks
Sadish
Ryan, are there any plans to provide supplementary template functions (in addition to existing ones like
single_tag_title) so as to allow theme authors to access (for example) multiple tag names through the API? Tag archives would be much improved if we could display all the queried tags, not just the first one.This is not the wordpress bugreport page but…
There seems to be a problem with using foreign characters in wordpress tags? The swedish åäö doesn’t work in the wordpress tag system. And i got a tag subdirectory with both “sang” and “sång”.How do i fix the problem?
Holy crap! We’ve been waiting for this FOREVER!
#1 new feature, IMHO
It’s nice to see that you can use the + operator on WP tag queries.
I wonder if it’s possible to do the same with cats on 2.3. (I havent installed it yet, need to fix a bunch of stuff before upgrading)
On 2.2, you can’t query trough blog/?cat=5+3
using cat=5,3 will use OR instead of AND. Hopefully, with the new taxonomy scheme you can use this same query for cats.