WordPress Guy

WordPress Guy designs and develops WordPress themes and plugins. WordPress Guy teaches you WordPress stuff.

Did you know that WordPress supports multiple tag queries?

Let me explain. Imagine that you want to see all the posts tagged “music” and “apple”, well it’s as easy as:

http://yourblog.com/tag/music+apple

And if you want to see all posts tagged “music” or “apple” then:

http://yourblog.com/tag/music,apple

The same principle applies for categories.

Note: For those of you not using “pretty” permalinks, then it would be:

http://yourblog.com/?tag=music+apple or http://yourblog.com/?tag=music,apple

The only problem with this is that there is no way (that I know of) for doing such queries except typing the url by hand.

Comments

  • July 8th, 2008 at 8:05 am

    Very interresting post! I might check out your blog very often :)

  • December 4th, 2008 at 8:28 pm

    Well, all that you type as a URL generates a query.
    So, all that is able to return a result is based upon a query you can reproduce in a template file.
    As an example, I’m currently putting together a music label web site based upon Wordpress used as a CMS. In order to ease my client’s work when posting new data, each album is split into several posts so the template will format the page using some “if it has that tag + that tag, put the post there else…”. So, the query finally is something like “if(has_tag(x+y)” which I do through some WP_query and query_posts (using wordpress 2.6.x).
    You can see a working live example at this location: http://www.bonesbrigaderecords.com/?cat=3 and don’t trust the URL, the whole page is based upon brand new queries through WP_query.
    If you click on an album cover, it opens a new page. Each “category” of the page is a separate post.
    Yours,
    Kaos

  • December 6th, 2008 at 8:03 pm

    Seems to work well for Tags, but not for categories!?!

    Anyone have any more advice on this?

  • December 6th, 2008 at 8:19 pm

    Doesn’t seem to work for you either!

    For example:

    http://wpguy.com/category/articles,themes

  • kzil
    January 2nd, 2009 at 7:54 pm

    Nope, it doesn’t work for categories. Not with 2.7 and the K2 theme, at least.

  • June 27th, 2009 at 8:44 am

    I found you had to use “+” rather than “,”. For example:

    http://lowgicooking.com/tag/nutmeg+apple

  • Kaan
    August 2nd, 2009 at 1:42 pm

    I’m lookoing for just this feature! But I can’t seem to find the solution.
    Has anyone found an answer to question of why it doe snot work? Has it to do with the WP version, or installed plugins?

    Hoping to hear from you,
    Kaan

  • alextoul
    May 4th, 2010 at 9:09 am

    Hey!

    Thanks for your post! There’s a way to avoid to type it manually. You just have to build a search bar.

    then on the page which receive the POST. On the top of the page.

    $_GET['tag'] = str_replace (” “,”+”,$_POST['keyword']);

    • July 22nd, 2010 at 11:23 pm

      Hey There! I’m trying to create a multiple select form with my tags. How does $_GET['tag'] = str_replace (” “,”+”,$_POST['']); work? All I need is to replace the “&tag=” from the URL query string and replace it with a “+”

      • lisa
        November 2nd, 2010 at 9:12 pm

        So does this work? I cannot get it to work.

  • Jay
    June 3rd, 2010 at 1:45 pm

    thnx, totally forgot this.

  • June 30th, 2010 at 10:30 pm

    ... Multiple tag / category queries | WordPress Guy ...

  • fabbrillo
    July 9th, 2010 at 2:27 pm

    you might want to try sk-multi-tag plugin, it’s not really easy to configure but works great

  • September 22nd, 2010 at 1:32 pm

    And does anyone if it’s possible to do the same but for a feed (RSS) URL using multiple tags? I can’t get it:

    example: WORDPRESS_URL/tags/babys+child/feed

    Thanks!

  • January 20th, 2011 at 6:15 pm

    @Alex: Your Url looks alright. Multiple Tags should also work with feeds.

    Look for example at this feed on:
    http://www.piratenspielzeug.com/tag/lego+piraten/feed

    Wordpress is a bit clumsy about multiple tags:

    On the one hand the title is not created correctly for this pages and the header-tags are also wrong.

    To fix that (and to fix that RSS-Feed, which is also not working automatically) I created the Wp-Plugin MultiTags http://www.vogel-nest.de/wp_multitags_plugin

    Sadly you have to mess a bit with the core to have the RSS-functionality, because WP doesn’t allow to rewrite the default RSS-Feed in that case.

    But the FAQ of the plugin describes how to do that.

  • April 7th, 2011 at 10:32 pm

    Try Wordpress Plugin: sk Multi Tag

  • April 17th, 2011 at 5:15 pm

    The /tag/tag1+tag2 search capability broke after the update from WP 3.1 -> 3.1.1 Instead, it returns an “OR” result, rather than an “AND”. Also, WP 3.1.1 no longer returns a “not found” if a particular tag intersection does not exist.

  • June 3rd, 2011 at 10:03 pm

    ... Multiple tag / category queries | WordPress Guy (tags: wordpress) ...

  • March 19th, 2012 at 1:06 pm

    thanks for sharing great article will open view your site at any time.

  • laurent
    May 4th, 2012 at 1:41 pm

    How to do the same with category ?
    Thx

  • August 17th, 2012 at 5:10 am

    Is there any way to do this automatically through php code?

    I run a web label and I’d like to be able to separate media types into sections (already done), but have similar ones all in one group (like albums and EPs). I can’t put them all in one group because the different ones help with different CSS details (like icons that differentiate between albums and EPs).

    The Wordpress site doesn’t seem to have much info on that particular method.

  • November 21st, 2012 at 11:19 pm

    ... To do a double selection by tags use blog.wordpress.com/tag/tag1+tag2. (Thanks wordpress guy.) ...

  • November 25th, 2014 at 2:18 am

    OMG (<–I don’t use that abbreviation often), thank you so much for this post. I couldn’t find documentation on this function ANYWHERE!

    It’s incredibly useful for providing static menu access to certain categories, e.g., organizing the blog into a website by category or even tags. THANK YOU!

Your Comment