How to activate user search in wordpress

I’m trying to activate the user search in my wordpress site. Which means that I want also the users on the search result. I have tried some plugins, but none of these gives the solution I want. Is there some code snippet that I can put on functions.php that helps to solve my problem? Do I have to use WP_User_Query? Thanks!

So far I have used these plugins:

  • Relevanssi
  • Search everything

Related posts

Leave a Reply

1 comment

  1. This is not perfect but might help.
    You can create a search template and create your user query after/before the main loop like this:

    $search = get_query_var( 's' );
    $user_query = new WP_User_Query( array(
      'search' => "*{$search}*",
      'search_columns' => array(
            'user_login',
            'user_nicename',
            'user_email',
            'user_url',
      ),
      'meta_query' => array(
            'relation' => 'OR',
            array(
                  'key' => 'first_name',
                  'value' => $search,
                  'compare' => 'LIKE'
            ),
            array(
                  'key' => 'last_name',
                  'value' => $search,
                  'compare' => 'LIKE'
            )
      )
          ) );