I am looking on all the internet but I can't find the answer. I want to add a column in the users administrator list to sort by user role. I don't know programming and i can't find a plugin (Admin Columns pro don't do this). I know for sure it's a simple function to the functions.php . If anyone can help me will be nice. This answer is not anywhere in the internet


Add this code to functions.php of your current theme ( preferably, child theme ):

function wpse_user_sortable_columns($columns) {
    $columns['role'] = 'role';
    return $columns;
add_filter('manage_users_sortable_columns', 'wpse_user_sortable_columns');

This will change Role column to be sortable.

  • It is indeed sortable that way, but it orders by username still, not Role alphabetically as you would have expected - roles are stored as serialized array (and user can have multiple roles), so you have to create your "main role" column (or whatever) and sort that based on custom pre_get_users(). See wpquestions.com/… – trainoasis Mar 13 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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