Home Articles Multiple tag / category queries

Multiple tag / category queries

2687
23
SHARE

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.

23 COMMENTS

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

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

  3. 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’]);

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

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

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

  6. @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.

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

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

  9. 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!

Comments are closed.