Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Edit: Welp, I earned a tumbleweed. Maybe it would help to rephrase? (I also rephrased the title).

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
add comment

1 Answer

up vote 8 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
add comment

Your Answer

 
discard

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.