I’m trying to set a custom page when the search comes up with no results
The site also uses advanced woo search plugin, but I do not think that controls.
Hey mnydish,
Thank you for the inquiry.
There is no option for this by default, but you can try this code in the functions.php file to redirect to a custom page when no posts are found.
function av_redirect_no_search_results() {
if ( is_search() && !have_posts() ) {
wp_redirect( home_url( '/unfortunately-we-dont-have-what-youre-searching-for/' ) );
exit();
}
}
add_action( 'template_redirect', 'av_redirect_no_search_results' );
Best regards,
Ismael
That works great! thank you