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.
Very interresting post! I might check out your blog very often π
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
Seems to work well for Tags, but not for categories!?!
Anyone have any more advice on this?
Doesn’t seem to work for you either!
For example:
http://wpguy.com/category/articles,themes
Nope, it doesn’t work for categories. Not with 2.7 and the K2 theme, at least.
I found you had to use “+” rather than “,”. For example:
http://lowgicooking.com/tag/nutmeg+apple
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
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 “+”
So does this work? I cannot get it to work.
thnx, totally forgot this.
[…] Multiple tag / category queries | WordPress Guy […]
you might want to try sk-multi-tag plugin, it’s not really easy to configure but works great
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!
@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.
Try WordPress Plugin: sk Multi Tag
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.
[…] Multiple tag / category queries | WordPress Guy (tags: wordpress) […]
thanks for sharing great article will open view your site at any time.
How to do the same with category ?
Thx
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.
[…] To do a double selection by tags use blog.wordpress.com/tag/tag1+tag2. (Thanks wordpress guy.) […]
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.