[wp-hackers] custom post types: order by taxonomy
mark at simplercomputing.net
Mon Mar 7 23:43:00 UTC 2011
On 03/07/2011 01:31 PM, Otto wrote:
> It's not possible to order by terms in a taxonomy, because it doesn't
> make any real sense to do so.
> Taxonomies are ways to group things together. So the point of having a
> taxonomy on posts would really be to have terms in that taxonomy that
> are shared between posts. If a taxonomy had terms that were only used
> on one post each, then that would make the taxonomy kind of pointless.
> And if the terms were shared like they should be, then ordering by it
> wouldn't produce anything particularly useful.
> What you should be using in such a situation is the post meta. You can
> order by post meta, and it's unique to each post.
I'm well aware of why taxonomies exist. I didn't provide enough info in
the original post, and I've since did some testing. Here's a pseudo
Example: post type is music; taxonomies are genre, artist, and label.
Then there are 57 posts in that type, some have all values in the
taxonomies set, some only have 2, some only have 1 -- all because maybe
someone didn't know the label or whatever, so they made posted but only
chose terms in 2 of the taxonomies, leaving the 3 one unset.
Then, on the site there's a list of music posts shown in a table. If I
want to sort those posts by any of the 3 taxonomies then it's no big
deal to do that. I can sort by term name, no problem. The problem arises
when querying for posts by taxonomy, because some posts are missing a
taxonomy setting (e.g. no label defined). If I use tax_query to get a
list of posts in the label taxonomy then any posts that don't have the
label set are not show. That isn't the desired result.
So I have to dream up some other way to deal with that problem without
forcing someone to always set terms in all 3 taxonomies.
More information about the wp-hackers