2

It seems I have a similar problem to the one described in this thread.

You enter a search query and get redirected to the correct URL but the page displays the system message template saying Your search did not return any results instead of redirecting to the no-results template.

Removing the exp:search:search_results tag causes the page to render correctly, but obviously without any search results in it. {exp:search:total_results}{total_results}{/exp:search:total_results} also shows up as 0.

So why doesn't EE redirect to the no-results template if there are no results? Although it doesn't seem to matter what I enter, I get the error message each time.

Template code

Form

{exp:search:simple_form
    channel="blog"
    no_result_page="{segment_1}/search/no-results"
    result_page="{segment_1}/search/results"
    search_in="everywhere"
    where="all"
}
<input type="text" name="keywords">
<input type="submit" value="Go">
{/exp:search:simple_form}

Results

<p>There were <strong>{exp:search:total_results}{total_results}{/exp:search:total_results}</strong> results for a search for <em>{exp:search:keywords}</em>.</p>

<ul class="search-results">
{exp:search:search_results}
    <li>
        <a href="{auto_path}/">{title}</a>
    </li>
{/exp:search:search_results}
</ul>
0
1

It's a bug in EE's native Search module. Bug reported here: https://support.ellislab.com/bugs/detail/19828

Here's the fix:

Starting in line 1290 of system/expressionengine/modules/search/mod.search.php

REPLACE

if ($query->num_rows() == 0 OR $query->row('total_results')  == 0)
{
  return ee()->output->show_user_error('off', array(lang('search_no_result')), lang('search_result_heading'));
}

WITH

if ($query->num_rows() == 0 OR $query->row('total_results')  == 0)
{           
  if ($query->row('no_result_page') == "")
  {
    return ee()->output->show_user_error('off', array(lang('search_no_result')), lang('search_result_heading'));
  }
  else
  {
    $path = reduce_double_slashes(ee()->functions->create_url(trim_slashes($this->_meta['no_result_page'])).'/'.$hash.'/');
    ee()->security->restore_xid();
    return ee()->functions->redirect($path);
  }
}
6
  • Given that you posted exactly the same answer on the other thread, can we close this one as a duplicate? Oct 21 '13 at 6:38
  • Yeah, of course. But the other one needs at least an up vote first. Oct 21 '13 at 10:28
  • Done. @Tyssen let me know if Stephen's answer doesn't solve your problem and we can reopen this question. Oct 21 '13 at 17:38
  • 1
    Not quite. That fixes the system template error issue, but I'm still ending up at the results template with it saying that there are 0 results instead of the no-results template. Should I be following this up with EllisLab instead?
    – Tyssen
    Oct 21 '13 at 23:55
  • Definitely chime in on the bug report linked above. Oct 22 '13 at 0:03

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