I’m trying to add sorting on Role column on user listing by desc and asc but I can get it work, it always show “No matching users were found.” below are my code

add_filter( 'manage_users_sortable_columns', 'wp420_user_sortable_columns' );
function vma_user_sortable_columns( $columns ) {
    $columns['role'] = 'role';
    return $columns;
}
add_action('pre_user_query','wp420_pre_user_query');
function wp420_pre_user_query($user_search) {
    global $wpdb,$current_screen;
    if ( 'users' != $current_screen->id )
    return;
    $vars = $user_search->query_vars;
    if ('role' == $vars['orderby']){
        $user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key='wp_user_level')";
        $user_search->query_orderby = ' ORDER BY UPPER(m1.meta_value) '. $vars['order'];
    }
}

Read more here: Role Column Sorting


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, ,

Wordpress related questions and answers: