Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

When using the search form, by default Drupal searches Content nodes, and there's a toggle to search Users (search/node vs. search/user). But the search/user appears to only search the default fields for the User nodes (username and email). I've added additional fields (Admin > Config > People > Manage Fields) to User nodes, but those don't get searched. How can I make the default search/user find users by those additional fields?

share|improve this question

2 Answers 2

As far as I know, the easiest way to do this is with views. You can set up a user view with exposed filters for any user field that you need to search. If you want to get a link to your your view on the search page form then, a form alter in a custom module would do it. Obviously make sure your view has a page with a proper path setup. search/your_view etc will work.

Here is a quick example of adding a custom markup field to the search form in drupal 7.

function CUSTOMMODULENAME_form_alter(&$form, $form_state, $form_id) {

 if ($form_id == 'search_form') {

   $form['usercustomsearchlink'] = array(
  '#type' => 'markup',
  '#markup' => '<a href="http://YOURSITE.com/search/YOURVIEWNAME">Search User Fields</a> ',
  '#weight' => 1,
   );

   }
}

That should put a link underneath the search box on the form (after a cache clear). However, I havent been able to figure out how to make it appear only on search/user pages yet so, that link will appear on all search forms.

share|improve this answer

I recommend trying the Search by Page module. You can search user fields by adding which roles are to be added to the index and which role is to be used when doing the indexing. The results are added to the default search page by adding another search tab in addition to "Content" (nodes) and "Users".

The module also has an API to help add other things to to the index. But, making user fields searchable can be done with configuration alone via the included sub-module.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.