Watch other videos on our YouTube channel. Click here to subscribe.
I was recently looking at all the default views that come with Drupal 8. For people who don’t know, the Views module is part of Drupal 8 core. In Drupal 7 and below it’s the most installed module so during Drupal 8’s development it was decided to move Views into core.
During my exploration into all of the default Views, I noticed that in the People (User) view there was a filter called “Combine fields filter”.
Want to learn about Views? Read Build a Blog in Drupal 8: Using Views or watch it as part of our FREE Drupal 8 Site Building course.
Now just a quick side note, if you’re new to Drupal and Views I’d highly recommend you spend time walking through all of the default views and see how they were configured. You can learn a lot just by seeing how things are set up.
The “Combine fields filter” does a pretty cool thing. It allows you to search across multiple fields or put another way, it allows you to combine fields and then filter by their combined value.
How to use “Combine Fields Filter”
Using this filter is relatively straightforward. Just click on Add in the Filter criteria field-set. Search for the filter by name or select Global from the Category drop-down.
When configuring the filter, you can select which fields you want to search from the “Choose fields to combine for filtering” drop-down.
If you want to see what the actual query looks like, turn on “Show the SQL query” from the Settings page (admin/structure/views/settings).
Then in the preview area, you should see the query that gets generated.
The above example is from the “People (User)” view.
Summary
If you want to add basic filtering across fields to your views, then this is the way to go. It’s useful for those custom admin pages which we create to help editors manage content. If you’re looking for something more advanced such as keyword searching, then look at using Search API.
A really good trick is to use “Force using fields” (format settings for the display) when using say Content Teaser for your display. This allows you to take advantage of the combined field filtering, while using a display mode for the output.
Hi Si,
Thanks for the tip.
Cheers,
Ivan
Hey mate, loving your guides. I have found you cannot add complex fields like a multi select list. Is there any alternatives to this that will combine a complex type?
Hi Jake,
It won’t work on complex field types, unfortunately.
You can look at Search API, but that’s a whole search engine built for Drupal. And requires a lot of configuring.
Cheers,
Ivan
Thanks for this solution!
I had two different year fields used for two different content types. I was able to combine them so they display in one column of my View. The only problem I have now is that I can’t sort on the combined field. Is there a way to do that?
Thanks for your help!
I don’t think you can use a combine field to sort.
You’ll need to come up with another solution. I don’t know what the solution could be as I don’t know how your site’s been built.