I'm trying to create sortable column headers for a CPT list, but I'm stuck on one piece. When clicking on an "Assignee" column head, I want the list to display alphabetically by the login name of the user.
The following in
pre_get_posts sorts by the user ID (saved as the meta_value via Advanced Custom Fields):
$query->set('meta_key', 'assignee' ); $query->set('orderby', 'meta_value' );
However, I'd like to order not by ID but the user_login it corresponds to.
I've successfully used code from this article (http://scribu.net/wordpress/sortable-taxonomy-columns.html) for taxonomy sorting (in a different column), but I can't figure out how to apply the same technique to the user table.
I've tried variations of something like the below in the
posts_orderby filter, but I'm way off.
SELECT GROUP_CONCAT(user_login ORDER BY user_login ASC) FROM $wpdb->users INNER JOIN $wpdb->postmeta ON $wpdb->postmeta.meta_value = ID INNER JOIN $wpdb->posts ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE $wpdb->postmeta.meta_key = 'assignee' GROUP BY user_login
I really appreciate your help!