Taxonomy Intersections and Unions

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.

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 thoughts on “Taxonomy Intersections and Unions

  1. […] 另外還有一些外掛/佈景主題製作者才可能用到的新功能,這部份請看原文吧!看起來很好用,外掛可以寫得更加抽象了! This entry was written by BCSEEATI, posted on October 2nd, 2007 at 03:10:01, filed under 言語 and tagged taxonomy, WordPress. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL. « Bad Behavior […]

    Like

  2. 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

    Like

  3. 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.

    Like

  4. 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?

    Like

  5. 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.

    Liked by 1 person

  6. […] A potential solution lies in making the best of Software: TDO Tag Fixes WordPress Plugin [ thedeadone.net ]: did you know that you can display multiple tags in the one archive and even generate a feed for that? WordPress 2.3 introduced native tagging support, which is rather nifty. This plugin is simply intended as an example of how to implement tag and category intersections. [see Boren on “Taxonomy Intersections and Unions”] […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s