A client has requested to have two kinds of custom user roles, and have those users displayed in an Admin Menu Page of its own. So far, I've achieved that using WP_List_Table with success.

Now, the next request is to not display those users with those custom roles in users.php. So far, I haven't been able to accomplish this because I can't seem to find documentation about customizing the users.php User Query that runs in that page, or a filter that allows me to do so programatically. Not even a plugin.

Where can I get some info or documentation about this? Or should I reimplement users.php?

1 Answer 1


pre_get_users is the action that is fired before a user query is run. You need to check the context of the action to make sure you're on the main users screen. You can then alter the query with any parameters accepted by WP_User_Query.

A quick example:

function wpd_filter_users( $query ) {
    $screen = get_current_screen();
    if( is_admin() && 'users' == $screen->base ){
        $query->set( 'role', 'Subscriber' );
add_action( 'pre_get_users', 'wpd_filter_users' );
  • 1
    Thanks for the answer, it was exactly what I was looking for. The only difference was that, as I needed to exclude some user roles from the query, all I did was change 'role' to 'role__not_in' in the $query->set statement, and give it an array with the roles I needed to exclude from the search. May 12, 2016 at 14:39

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.