I'm using Register Plus Redux plugin to augment a registration form with custom metadata fields. These fields display at the bottom of each user record detail page and they can be retrieved with get_the_author_meta.
In addition, I'm able to create columns in the User panel (the list view) and to make these columns sortable. The problem is that, when I click on the custom column heading, the orderby= value in the URL appears to be ignored. Put another way, it appears the query that generates the list view of users does not include the custom meta data (e.g. perhaps it requires a join statement if the metadata is not in the usual place for user data?). It feels like I've missed a step.
Here is my code to create the custom columns:
//add columns to User panel list page
function add_user_columns( $defaults ) {
$defaults['company'] = __('Company', 'user-column');
$defaults['title'] = __('Title', 'user-column');
return $defaults;
}
function add_custom_user_columns($value, $column_name, $id) {
if( $column_name == 'company' ) {
return get_the_author_meta( 'company_name', $id );
}
if( $column_name == 'title' ) {
return get_the_author_meta( 'titlefunction', $id );
}
}
add_action('manage_users_custom_column', 'add_custom_user_columns', 15, 3);
add_filter('manage_users_columns', 'add_user_columns', 15, 1);`
And here is my code to make these columns sortable:
function user_sortable_columns( $columns ) {
$columns['company'] = 'Company';
return $columns;
}
add_filter( 'manage_users_sortable_columns', 'user_sortable_columns' );
function user_column_orderby( $vars ) {
if ( isset( $vars['orderby'] ) && 'company' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'company',
'orderby' => 'meta_value',
'order' => 'asc'
) );
}
return $vars;
}
add_filter( 'request', 'user_column_orderby' );`
Any ideas how I can update the query that generates the list of users so that it includes sorting by my custom field(s)? Or, if that's not the problem, how to make the custom column headings sort the list of users when clicked?
Thank you.