Role Column Sorting

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;



function wp420_pre_user_query($user_search) {

    global $wpdb,$current_screen;

    if ( 'users' != $current_screen->id )

    $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

Leave a Reply

Your email address will not be published. Required fields are marked *