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?

1 Answer 1


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

  • i've been wondering how to do this for days :) Commented Jul 25, 2011 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
    Commented Jun 9, 2012 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_taxonomy_id) AND (taxonomy = 'color' OR taxonomy IS NULL), remove the where clause, and then it works. See stackoverflow.com/a/5426105/126272
    – jessica
    Commented Jun 9, 2012 at 3:26
  • Also need to change the GROUP BY to ID, not object_id.
    – jessica
    Commented Jun 9, 2012 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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