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 “+”

  • 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

Your Comment