I have a simple content type in Drupal 7 with title and body (and other fields). I've defined a view with exposed filters.

I want just one text field that searches in title or body. So, if I search for 'foo' both nodes with 'foo' in their body or/and title will be matched.

One solution is to use "Global: Combine fields filter" and combine title and body, but Views then uses a CONCAT function in where clausule, something bad for performance.

I've a solution, but there're drawbacks and I'm not sure if it's optimal.

1 Answer 1


Using Vies or/and funcionality I set (using more fields not related to this question):

filed1 AND field2 AND ... fieldN AND title OR body

title is not expsed, but body is.

My solution is to implement hook_views_pre_build(&$view).

if ($view->name == 'my-view') {
  // Look for the search string, is it present?
  if (!empty($_GET['search'])) {
    $view->filter['title']->value = check_plain($_GET['search']);

I've renamed body key in GET to be search.

This way search is performed as I want. The drawback is I can't position search element anywhere becasue it must be in its own group, but I can live with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.