Does anyone know how to fix this?
Anonymous User 8859655
(@anonymized-8859655)
czcsabi’s wpse_27518_pre_user_query addition to function.php makes sorting work fine for me.
How did you implement it exactly?
Anonymous User 8859655
(@anonymized-8859655)
I just added the code into functions.php: From the Admin menu, select Appearance/Editor, then Theme Functions (functions.php).
<?php
add_action('pre_user_query','wpse_27518_pre_user_query');
function wpse_27518_pre_user_query($user_search) {
global $wpdb,$current_screen;
if ( 'users' != $current_screen->id )
return;
$vars = $user_search->query_vars;
if('wp-last-login' == $vars['orderby'])
{
$user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key='wp-last-login')";
$user_search->query_orderby = ' ORDER BY UPPER(m1.meta_value) '. $vars['order'];
}
}
Strange, it has worked in one of my sites, but not in another.
It also doesn’t sort if you are in a multisite installation and are a looking at wp-admin/network/users.php . It does if your are looking the user list of one site in the network,
Thanks roddyp