How to change the order in which users are displayed in admin?

I would like to change the order in which users are displayed in the admin. At the moment it seems that they are order by the username.

I think I have found the right place in the wp-admin/users.php, which is around line 187:

Read More
ORDER BY user_login");

I am not 100% sure if this is right as I don’t know much about the code. Could anyone confirm if I am in the right place and what I should do to change the order.

Also is it only possible that I could have an ascending or descending order for example, A,B,C,D,E or E,D,C,B,A?
It would be idea if I could specify the order differently, for example, C,A,D,B,E or similar.

Thanks

Related posts

Leave a Reply

1 comment

  1. Nope, the line you found seems to be some basic preliminary query. Selection of users for display in table seems to be handled by WP_User_Search class. Luckily it can be hooked into easily.

    Try this (changes order to descending):

    add_action('pre_user_search', 'change_user_order');
    
    function change_user_order($query) {
    
        $query->query_orderby = ' ORDER BY user_login DESC';
    }
    

    PS I am not sure if this can interfere with something else, so might require checks to only run on that specific page.