Recently I developed some functionality for a client that I realized might be useful to the greater Drupal community. This post describes how to set up a combined fields filter in Views to allow searching for terms and matching more than one field.

Let’s say you have a single search box and you want to be able to match more than one field, in this case, a user’s first, or preferred name (both different fields on the user entity). Using a view with exposed filters to show the results, we can use combined filters to make this possible.

If there is a user named David who has the preferred name set as "Dave", he won’t show up for search results as "Dave" with our original view:

How to do a combined name search in Drupal

So we want to update this view to allow him to be found by searching for David or Dave. First, the view display is set up with the appropriate fields:

How to do a combined name search in Drupal

We modify the view, replacing the exposed filter for First Name with a Combine Fields filter. This lets you select multiple fields for combining. We can set the label the same as the First Name filter so the user will not know the difference. Select the two fields that need to be combined and apply the changes to the display.

How to do a combined name search in Drupal

Once these changes are made, search results now return the relevant user in both searches:

How to do a combined name search in Drupal

Once this is done, your view is now configured to search multiple fields for an optimized user experience. It’s recommended to export these changes to a feature to capture the changes in code.

Additional Resources

A Business Case for Features | Mediacurrent Blog Post

Drupal Features Module 101 | Mediacurrent Blog Post

Conditionally Open a Link in a New Tab in Views Without the PHP Filter | Mediacurrent Blog Post

Redirects
/blog/how-to-do-combined-name-search