2

I am using Views (7.x-3.0-beta3) and I have created a exposed text filter to a view, which work fine.

The problem is the default result value: when the field is empty, is displaying all possible results. But I want to display the empty result by default. If you have a solution please shear it.

3

You can use a views preprocessor to achieve this. The 'empty' element behaves similarly to the "No Results Behavior" option in the Views UI. Place this code in template.php and clear the cache:

function mytheme_preprocess_views_view(&$vars) {
  if ($vars['view']->name == 'my_view_name') {
    if (empty($vars['view']->exposed_input)) {
      $vars['rows'] = array();
      $vars['empty'] = '';
    }
  }
}

Tested using Views 7.x-3.0-rc1.

1
  • I am having similar requirement. Where exactly should this code be added? can I add it in views.php? – Rick Dec 11 '19 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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