Filters the columns to search in a WP_User_Query search.
The default columns depend on the search term, and include ‘ID’, ‘user_login’, ‘user_email’, ‘user_url’, ‘user_nicename’, and ‘display_name’.
$search_columnsstring[]
$searchstring
$queryWP_User_Query
The user_search_columns filter is used to determine which user fields in the database are used when performing a search on user information.
When the ‘user_search_columns’ filter is called, it is passed three parameters: an array of fields to search, the search term, WP_User_Query object
<pre>add_filter( 'user_search_columns', 'filter_function_name', 10, 3 );
function filter_function_name( $search_columns, $search, $wp_user_query ) {
// Alter $search_columns to include the fields you want to search on
return $search_columns;
} Where ‘filter_function_name’ is the function WordPress should call when the filter is run. Note that the filter function must return a value after it is finished processing or the search terms will be empty.
filter_function_name should be unique function name. It cannot match any other function name already declared
$search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this );
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/hooks/user_search_columns