Search results when none found – stay on page they were on
Not sure it is a smart thing* to do but it is possible. The easy solution is to check if you have any posts and if not redirect based on the referer At the top of your code (before the call to get_header) add if ( !have_posts() ) { if (isset($_SERVER[‘HTTP_REFERER’])) { wp_redirect(301,$_SERVER[‘HTTP_REFERER’]); } } … Read more