[wp-hackers] Limitations and Patch for WP_Query Taxonomy Stuff
Joe Hoyle
joehoyle at gmail.com
Wed Dec 30 16:53:42 UTC 2009
Hi Everyone,
I wanted to discuss some a limitation I have come across several times when querying: querying for posts by multiple taxonomies. Currently you can do things like category__in, category__not_in etc which is good, if you only want to query tags or categories. However, if you have a few extra taxonomies set up, you are restricted by query for one term in a single custom taxonomy. I created a patch here: http://core.trac.wordpress.org/ticket/9951 which adds support for $tax__in, $tax__not_in (this patch needs some work, it is really a proof of concept).
After mulling over that for a while, it got me thinking. Whats the point in even having category__in, and tag__in duplicated in the query class (not to mention category__not_in, category__and, category__slug_in or whatever etc etc...). Why not have this querying by taxonomy (be it categories, tags, manufacturers, companies etc etc) all dealt with by the same code. The only issue then is the annoying difference between tag__in, and the taxonomy name which is post_tag. We have an array of registered taxonomies (post_tag, category, manufacturers) simply check the query vars for an registered taxonomies: *__in, *__not_in, *__slug_in, *__and blah blah blah. This we I can query by any amount of terms in any amount of taxonomies be they custom or "normal".
I have also written an experimental patch: http://core.trac.wordpress.org/attachment/ticket/9951/tax-experimental.diff which gets rid of all the category__not_in, tag__not_in stuff and replaces with checks off of all registered taxonomies. Again, this needs some work; for example hardcoding the 'tag__' to 'post_tag__' etc, but I wanted to get a proof of concept out to see how it could be done.
Personally, I think the more WordPress is used for more complex data / custom post types the more custom taxonomies will be used, and not having the ability to query for any amount is going to be limiting. I just wondered if anyone else thinks this is something worth pushing for in core, or anyone fancies writing in improved patch etc.
Cheers
Joe
More information about the wp-hackers
mailing list