[Solved] Using wp_query is it possible to orderby taxonomy?


No, it is not possible to order by taxonomy, because from a certain type of standpoint, that doesn’t actually make much sense.

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.

Edit: That said, you can order by taxonomy by making a custom SQL query using a filter, you just can’t do it from a unmodified WP_Query: http://scribu.net/wordpress/sortable-taxonomy-columns.html

However, if you’re having to resort to doing this sort of thing, then your data design structure is wrong in the first place. “Terms” in the taxonomy are not actual “data”. The terms themselves have no inherent meaning, they’re just labels for the particular grouping that they’re describing. If you’re treating them as meaningful data, then you have an underlying design flaw.

Taxonomies group things by assigning terms to them. That grouping is the whole point of taxonomies, the terms are just pretty faces on the grouping. If you have meaningful metadata to assign to a post, then you should be using the post meta for it instead. And that you can order by, because post meta uses both keys and values to store information. With a taxonomy, you’re really only storing keys, with their values being the posts grouped together by that term.

Things are easier in the long run if you use the correct approach for it. While I’m not saying that you can’t do something strange with taxonomy, you’re just making things harder for yourself in the long run by using it wrong.

14

solved Using wp_query is it possible to orderby taxonomy?