I'm looking for a way to modify the search query if the performed query returned no results.
Let's say I'm looking for "Opening times", so I go to this URL:
http://mysite.com?s=Opening+times
Now, in my search.php
I want to check if that query gave no results, and in that case, I want to perform a new query with a different term, wihtout any required action by the user.
Something like this:
global $wp_query;
$total_results = $wp_query->found_posts;
if ( $total_results == 0 ) {
// Create a new query with the terms 'Find Us'
}
// Display results (either those for the 'Opening times' query or for the 'Find Us' one if the former didn't return any result)
Is there an easy way to do this?