1

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:

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

1 Answer 1

2

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.

2
  • thanks, so is it right that only ascending and descending options are available for sorting or is there another method?
    – chentudou
    Commented Dec 14, 2010 at 10:41
  • You can change this to anything that makes sense to MySQL, this changes part of SQL request that is run to fetch users from database.
    – Rarst
    Commented Dec 14, 2010 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.