5

What is the best method (as of 3.1 or 3.2 beta) to sort a custom post type archive by a given taxonomy term?

I'm trying to make a staff page and I want to sort employees by department. So the taxonomy would be staff and the terms to sort would be sales and support.

I tried query_posts and WP_Query but perhaps I messed up the arg array...

4
  • 3
    For mutually exclusive terms use post meta not taxonomies. Sorting is easy then.
    – fuxia
    May 13, 2011 at 13:57
  • I thought of using post meta but as I understood it taxonomies are for grouping large numbers of posts within a few variables. If I can't find a good way to do it with taxonomies I will definitely have to go this route...
    – MTT
    May 13, 2011 at 23:41
  • 1
    One object may have more than one taxon from each taxonomy. That’s the basic difference to post meta values. The other: Queries for post meta touch just two tables, not three like for taxonomies.
    – fuxia
    May 13, 2011 at 23:51
  • old post, but for anyone looking this is how i solved it: wordpress.stackexchange.com/questions/38075/… Jul 17, 2012 at 20:12

1 Answer 1

0

Good question - I'm fairly sure you can't do this just using wp_query.

You'll need to either add a posts_groupby filter, or just query the database directly. This previous question and answer might be helpful

Using wp_query is it possible to orderby taxonomy?

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