Reintroducing Drupal core's Views "Combine fields filter"

Published March 12, 2024
Adding the Combine fields filter screenshot in Views.

I was recently reminded of a Drupal core feature that I hadn't used in a long time - and was pleasantly surprised at how useful it is.

The Combine fields filter Views filter allows a site-builder to quickly and easily set up an exposed filter that searches multiple fields for a given search term. Think of it as a way to combine multiple exposed search filters into a single search box.

Setting it up is quite easy - just include all the fields that you want to search in the Fields section, marking them with Exclude from display as necessary (Unfortunately, Combine fields filter doesn't work with view modes.)

Then, add and expose a Combine fields filter to the view, and configure it to use all the fields you want searchable in the Choose fields to combine for filtering section of the filter's configuration:

Configuring the Combine field filter in Views.

 

I created a simple example of a Movie content type with example fields including Title, Image, Plot summary, Spoilers, Year of release, Short description, Taglines, and Trivia. I added all of these fields to the Fields configuration of the view - with all of them hidden except for Title and Image.

Next, I added a Combine fields filter as described above, selecting all of the fields to be combined for filtering. Finally, I added a few sample Movie nodes.

To test things out, I searched for terms that were added as part of the various Movie content type fields (but purposely not words in the Title fields). The results were exactly what I was expecting!

In the first example, the word biff appears in the Plot summary field for Back to the FutureScreenshot of a search for "biff".
Next, the word saga appears in the Short description field of The Last Jedi.Screenshot of a search for "saga".
The number 1985 appears in the Year of release field of Back to the Future.Screenshot of a search for "1985".
Finally, the words Michael Caine appear in the Trivia field of The Dark KnightScreenshot of a search for "Michael Caine".


There are a few caveats when using Combine fields filter with one of the more impactful being that when utilizing a multivalued field (as the Trivia and Taglines fields are in the previous example), the Multiple field settings configuration cannot utilize the Display all values in the same row option. Fortunately, these fields are usually excluded (hidden) from search views like this. 

Multiple fields settings configuration - unselected - screenshot.

Comments

That is probably not a problem for most people, but I was trying to combine 100 fields and it wasn't possible. I had to create two combined filters. One can be used to search fields 1 - 50 and the second one 51 - 100.

Submitted by GD (not verified) on Thu, 03/14/2024 - 14:57

Add new comment

The content of this field is kept private and will not be shown publicly.

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA