Khanh Hoang - Kenn
Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.
Views offers the ability to expose filters to the end user so they may filter and sort through a views listing to find what they want in a large list of content. If you have used exposed filters before you will be familiar with exposing a filter on a specific field, such as the title field, for example. But what if you want the end user to be able to search in multiple fields at the same time?
Before we dive in, if you're unfamiliar with the terminology and functionality of views in Drupal, please visit the Views module documentation.
So to create an exposed filter that can let users search multiple fields at the same time, my first thought was to create a custom module with a views_query_alter() hook that would allow me to join fields together. This is not needed, however. Views 7.x-3.x allows you to expose one filter field to the end user for multiple field searching. Views offers a 'Global: Combine filter fields' option that allows you to pick one or more fields to filter on.
In a recent use case in a website we are building we had the following issue. In the screenshot below there is an exposed filter block to the left with an exposed title filter. This field allows end users to search for a title in the view listing to the right of the exposed filter block. This field works great if the user knows the full title of the content they are looking for but in practice many of these items are referred to with a short acronym. For example, the Achievement Rewards for College content item is also known as "ARCS." When using the title search field we would like the correct content to show up even if the user searches for ARCS. To do this we need a combined filter.
The following example will assume that you know the basics of creating views in Drupal.