Drupal - Expose single filter of combination of two fields in views
I eventually got a solution from this. I followed the second primary solution offered although the blogger personally used hook_views_query_alter()
.
- installed the module Views filters populate.
- added two filters "First Name" and "Last Name" (both must not be exposed) and added them to a OR filter group (Views 3 supports this). I had to use the operator "Contains any word" for both fields, otherwise the query gave me no desired result.
- created a filter "Global: populate filters", added the two fields into this and exposed it.
This gave me a quick solution without hard coding.
Here is other helpful reference.
On my installation, D7 with Views 7.x-3.6, you can add a filter that is " Global: Combine fields filter" which will do exactly what you need, allow users to search on multiple fields with a single filter.
Its really easy.
- Click on Add a filter.
- select "Global: Combine fields filter"
- Follow the instructions.
Thanks.