Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1467770

    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.

    #1467783

    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

    #1468080

    That works great! thank you

    #1468098

    Hi,

    Great, I’m glad that Ismael could help you out. Please let us know if you should need any further help on the topic, or if we can close it.

    Best regards,
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.