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:
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 Future. | |
Next, the word saga appears in the Short description field of The Last Jedi. | |
The number 1985 appears in the Year of release field of Back to the Future. | |
Finally, the words Michael Caine appear in the Trivia field of The Dark Knight. |
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.
Comments
Limited number of fields
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.
Hello Michael, thank you for…
Hello Michael, thank you for this useful reminder about the module.
Does it work with taxonomy ref fields?
Thanks
Good question
That's a very good question that I don't have the answer to! I would love to find out - maybe someone else has used it in that capacity and can leave a comment letting us know?
Add new comment