How do I redirect the user to some other page, when the view returns empty result?


2 Answers 2


In your views No results behavior Choose ' Global: Text area ' choose php filter and add the following code.

 drupal_goto('node/1'); //path to redirect

Better yet do it in your views-view.tpl.php and avoid using PHP in UI like.

  <?php if ($rows): ?>
    <div class="view-content">
      <?php print $rows; ?>
  <?php elseif ($empty): ?>
    <div class="view-empty">
      <?php drupal_goto('some_page'); ?>
  <?php endif; ?>

if you want to pass query to new url use this for goto

drupal_goto('your_url', array('query'=>array(
...... ...

or if you want to goto an anchor on page use this

drupal_goto("node", array('fragment' => $node->nid));

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.