I currently have a "store locator" proximity search setup very similar to the one detailed here: http://www.youtube.com/watch?v=AxeskzN8BAc.

The user enters a postcode, and receives results or no results as the case may be, for a given rectangular distance (say 100km around the entered postcode). Both postcode and distance are exposed filters.

If a node/marker isn't within the zone, I get no results. How can I dynamically modify or widen the distance so there are always some results? ie. How can I hook onto the exposed filter arguments and re-run the view for the no-results case?

3 Answers 3


I think the logic you should follow is to filter the results always with a maximum distance you want to show and sort the results by the distance and then limit the results to a specific number. That way you will always have results and you won't need to call the same view twice, which would impact the performance.

  • Like this answer though it doesn't have any Drupal related answer. I think this should be accepted :)
    – Gokul N K
    Mar 5, 2014 at 16:46
  • Both Bala and Елин Й 's answer helped but Елин Й's was the right logic. I was looking at it the wrong way around.
    – Mo Kargas
    Mar 5, 2014 at 21:11

You can call the view programatically and if no result are found call it again with new filter arguments.

For example: $view_id = 'your view id'; $display_id = 'your display id';

$view = views_get_view($view_id);
$view->preview($display_id, $views_args);

if (!count($view->result)) {
  // No results, call view again with other filter value.
  $filter_name = 'your filter name';
  $filter_value = 'your filter value';

  $view = views_get_view($view_id);
  $view->preview($display_id, $views_args);
  $view->display['default']->display_options['filters'][$fiter_name]['value'] = $filter_value;
  $view->preview($display_id, $views_args);

You will have to adapt it using your current filter name and right values. You can rewrite this example to modify the view all the times you need.

Put this code in a hook_menu callback returning the view.


I have a similar venue proximity search set up on my site, and when a customer searches for a venue and gets no results, I display a secondary view in the no results behaviour, showing all venues, with a message below saying "There were no results for the area you selected, please widen your search parameters, or manually browse for a venue near you using the map"

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.