WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type that uses a custom taxonomy. I'm imposing a limit of a single term to each post (using a custom meta box drop down on the edit post screen for the CPT). The term for the taxonomy is assigned using the standard wp_set_object_terms() function. How can I make the taxonomy column sortable (using WP 3.1rc3)?

This post by Scribu got me almost there.

However, since I'm not using a numeric value stored in a meta key, the {name}_column_orderby function will not work for me.

How can I create sortable columns within the manage-edit screens, when the information that I'm listing does not come from the post_meta table?

share|improve this question
up vote 9 down vote accepted

See the follow-up post: http://scribu.net/wordpress/sortable-taxonomy-columns.html

share|improve this answer
Thank you so much! – goto10 Mar 7 '11 at 15:19
i've been wondering how to do this for days :) – helgatheviking Jul 25 '11 at 15:20
@scribu Tried to comment on your blog post, but couldn't find a comment form; perhaps comments are closed. The updated function you posted from Mike doesn't work -- if a post has any taxonomies assigned, but not the one that's chosen for sort, it will disappear from the list. Still searching for an SQL statement that works, I'll post back if I find one. – jessica Jun 9 '12 at 2:57
@scribu I just figured it out. You need to limit the taxonomy in the join, not in the where clause. Change the 2nd join to: LEFT OUTER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id={$wpdb->term_taxonomy}.term_taxono‌​my_id) AND (taxonomy = 'color' OR taxonomy IS NULL), remove the where clause, and then it works. See stackoverflow.com/a/5426105/126272 – jessica Jun 9 '12 at 3:26
Also need to change the GROUP BY to ID, not object_id. – jessica Jun 9 '12 at 3:37

Your Answer


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.