Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
thanks, so is it right that only ascending and descending options are available for sorting or is there another method? –  chentudou Dec 14 '10 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 Dec 14 '10 at 11:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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