Searching for WordPress users by id.

Updated: 01 November 2022

From the Users screen

Searching for a WordPress user by ID is fairly straightforward from the Users Screen. Simply enter a user ID in the ‘Search Users’ box and press the button. Although the documentation (https://wordpress.org/support/article/users-screen/#search) states:
Any User that contains the search string in the Username, Name, E-mail, or Website fields will be displayed, by Role.
searching by ID also works.

Looking at the source code for class WP_Users_List_Table (https://core.trac.wordpress.org/browser/tags/6.0.2/src/wp-admin/includes/class-wp-users-list-table.php#L141) the user search is carried out using an instance of class WP_User_Query. If the search columns are not specified default search columns are set depending on the search term. If the search term is numeric the search columns default to user_login and ID (see https://core.trac.wordpress.org/browser/tags/6.0.2/src/wp-includes/class-wp-user-query.php#L717). Incidentally, this means that purely numeric search terms will not match email addresses.

From the command line

The syntax for searching for a WordPress user by ID using WP CLI is a bit obscure. The relevant section of the documentation for wp user list is:

[--<field>=<value>]
    Control output by one or more arguments of WP_User_Query().

The documentation for WP_User_Query includes the search argument, which is the necessary field. (See https://developer.wordpress.org/reference/classes/wp_user_query/#search-parameters).

Example: wp user list --search=317

As a side note, it is also possible to search by role using WP CLI.

Example: wp user list --role=subscriber

Leave a comment