• Resolved steveraven

    (@steveraven)


    Hi guys,

    We just started using Relevanssai for our search options in preference to the WordPress default search, and it’s playing a blinder with results!

    All that is, except one – which doesn’t get many search queries, but it’s more noticeable in relevanssai.

    So – assuming that we wanted to put a default page/post/cpt/no-search-terms-page type thing for those lazy buggers that just go to page one and hit the search with nothing in it, what would be the best way to send people to this new page presuming that the search page reads –

    ‘Search Results for “”‘

    and underneath that –

    ‘Sorry, no results were found for this query’?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    How about something like this?

    add_filter( 'relevanssi_modify_wp_query', 'rlv_empty_redirect' );
    function rlv_empty_redirect( $query ) {
        if ( empty( $query->query_vars['s'] ) ) {
            wp_safe_redirect( '/path/to/the/page' );
            exit();
        }
    }

    That should redirect all empty search queries to the specified page.

    Thread Starter steveraven

    (@steveraven)

    Looks good, my idea is to have a ‘404 page’ for blank searches with something like a cat video on it.

    I take it that the above snippet is added to functions.php?

    Thread Starter steveraven

    (@steveraven)

    Right, the above snippet works fine, except for a small problem – none of the REAL search terms are now showing their results and are going to the

    ‘Search Results for “real search term that was previously populated”‘

    and underneath that –

    ‘Sorry, no results were found for this query’

    page.

    Is there a fix for the snippet?

    • This reply was modified 6 years, 11 months ago by steveraven.
    Plugin Author Mikko Saari

    (@msaari)

    Hi,

    Oops:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_empty_redirect' );
    function rlv_empty_redirect( $query ) {
        if ( empty( $query->query_vars['s'] ) ) {
            wp_safe_redirect( '/path/to/the/page' );
            exit();
        }
        return $query;
    }

    That should work much better.

    Thread Starter steveraven

    (@steveraven)

    Works excellently, thanks @msaari

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search Results for People That Cannot be Bothered’ is closed to new replies.