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 responses to “Taxonomy Intersections and Unions”

  1. 你可能不知道的 WordPress Taxonomy 新功能 ¶ Lvx ex Cælis

    […] 另外還有一些外掛/佈景主題製作者才可能用到的新功能,這部份請看原文吧!看起來很好用,外掛可以寫得更加抽象了! 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 […]

  2. Sadish Avatar
    Sadish

    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

  3. Ben Eastaugh Avatar
    Ben Eastaugh

    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.

  4. 你可能不知道的 WordPress Taxonomy 新功能 ¶ Lvx ex Cælis

    […] 這些是外掛/佈景主題製作者才可能用到的新功能,詳情請看原文。這些新參數的使用方法大概是像這樣:(沒有測試過,不是很確定) […]

  5. Christer Avatar
    Christer

    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?

  6. jeremy clarke Avatar
    jeremy clarke

    Holy crap! We’ve been waiting for this FOREVER!

    #1 new feature, IMHO

  7. tricky Avatar
    tricky

    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.

  8. Ryan Boren on Tags and the Loop | Bloggercamp

    […] Boren puts out a basic introduction to tag handling Taxonomy Intersections and Unions. Related PostsTagging in WordPress 2.3How to Remove any Category from the LoopTop 5 SEO Tips for […]

  9. WordPress weekly digest 1st October to 7th October 2007 « westi on wordpress

    […] You can read more about the types of Category and Tag intersections supported by WordPress v2.3 in Ryan’s excellent post: “Taxonomy Intersections and Unions” […]

  10. Famous last words of Marius » IBM Patent, RWC and RSS feed update – 13 October 2007

    […] WordPress – What’s Right with WordPress 2.3 Taxonomy Intersections and Unions […]

  11. Ad-hoc article return using WP2.3’s tagging system : Kick ass! | The Wholesale Monkey Farm V2.0

    […] tags to get an ad-hoc return of posts based on the value of their tags, HandySolo pointed me to this solution. […]

  12. links for 2007-10-19 | Ge Xiaofei

    […] » Taxonomy Intersections and Unions boren.nu (tags: wordpress) […]

  13. WordPress 2.3.1 in detail « westi on wordpress

    […] improvements for the Taxonomy intersection queries […]

  14. My First Wordpress 2.3 Update Notification and Subversion Upgrade

    […] tag intersection search queries – #5137. Ryan Boren has written a good article on tag […]

  15. QUiXO BlOG » Nuovo aggiornamnto per Wordpress.

    […] improvements for the Taxonomy intersection queries […]

  16. WordPress 2.3.1 | DevStorming.com

    […] improvements for the Taxonomy intersection queries […]

  17. Antonio Trigiani w3bL0g – Informatica Virale » Blog Archive » Aggiornamenti Wordpress 2.3.1 security fix

    […] più performanti per la  Taxonomy intersection queries […]

  18. Metric Tensor / links for 2007-11-14

    […] » Taxonomy Intersections and Unions boren.nu (tags: wordpress tagging) […]

  19. Sonika’s blog » Немного о таксономии и тегах в WordPress

    […] по теме: Taxonomy Intersections and Unions (англ., автор boren.nu). Нет […]

  20. Categories and Tags – Search and Sort « Feet up, eyes closed, head back

    […] 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”] […]

Leave a Reply

Discover more from Ryan Boren

Subscribe now to keep reading and get access to the full archive.

Continue reading