Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it now possible to query multiple categories from the URL?

http://www.mywpsite.com/?cat=1+7

?

I think this has worked for tags for some time. If not, is there another way to achieve this?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

If you have a feature request for WordPress, the best way to get it addressed is to add a ticket on Trac. Then developers can adopt the task, patch WordPress, and submit the improvements to the next version. If a Trac ticket has already been created for a particular feature, you can comment on it to weigh in and follow the subsequent discussion.

The last time I checked, there was a ticket for querying multiple terms in a taxonomy (tags, categories, or custom) at the same time: Ticket #12891.

According to the ticket, the project is scheduled to be included in WP 3.1. But we won't know for sure until the first release candidate comes out. According to the last scope update before the feature freeze, this is going to be included in 3.1 ... but it won't be "fixed" until 3.1 is actually released.

If you want to use the feature now, you have a couple of options:

  1. You can download the actual patches from Trac and patch your WordPress installation to add the new functionality. I wouldn't recommend this because they may or may not depend on other 3.1 improvements that aren't included explicitly in these patches (i.e. improvements added by other tickets).
  2. Install the WordPress Beta Tester plug-in and upgrade to version 3.1-alpha. This would be the safest way to use the new feature, but still might cause problems! WordPress 3.1 isn't considered "stable" yet and some of the features/code might (will definitely) change before the final release date. There's no guarantee that the latest nightly build will be bug-free.
share|improve this answer
    
Great answer! Thanks! –  jnthnclrk Nov 5 '10 at 14:44
add comment

If you specify multiple category ID's separated by commas, they will be combined in category__in (or category__not_in if the ID is negative). category__in means the post must be in at least one of the specified categories (an OR query). category__not_in means the post must not be in one of the specified categories. The relevant code can be found in wp-includes/query.php, lines 1871 to 1909.

For tags you always have to work with slugs. If you separate them with commas, they end up in tag_slug__in, if you do it with plus signs they go into tag_slug__and. This means if you want an OR query you combine them with comma's, if you want an AND query you do it with plus signs. Here the relevant code starts at line 1946.

share|improve this answer
    
My example uses the plus sign for categories. That's what I'm interested in here. –  jnthnclrk Nov 5 '10 at 14:41
    
@trnsfrmr: My mistake, I looked over it. But you still got your answer: no, it is not supported at this moment. –  Jan Fabry Nov 5 '10 at 14:53
add comment

Or, you can use scribu's excellent Query Multiple Taxonomies plugin and get the functionality you want today...

http://wordpress.org/extend/plugins/query-multiple-taxonomies/

share|improve this answer
    
That's actually a bit different. This plug-in will let you query single terms from multiple taxonomies simultaneously (?genre=jazz&artist=chet-baker from the example). It won't let you query multiple terms from a single taxonomy simultaneously. –  EAMann Nov 5 '10 at 17:04
    
Actually, it does (have you tried it?) - I'm using it right now for this exact purpose. The example you mention isn't the only thing it can do... scribu.net/wordpress/query-multiple-taxonomies/qmt-1-1.html –  somatic Nov 6 '10 at 1:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.