How to search display_name column when using WP_User_Query

You can try this:

/**
 * Add support for the "display_name" search column in WP_User_Query
 * 
 * @see http://wordpress.stackexchange.com/a/166369/26350
 */
add_filter( 'user_search_columns', function( $search_columns ) {
    $search_columns[] = 'display_name';
    return $search_columns;
} );

where we use the user_search_columns filter to modify the available search columns.

So what fields can we use with this filter? Here’s the list of all the fields in the wp_users table:

x ID
x user_login
  user_pass
x user_nicename
x user_email
x user_url
  user_registered
  user_activation_key
  user_status
  display_name

where I’ve marked the default search columns with an x.

Leave a Comment