Site logo

[Support request] Site Search Pulling Back Unexpected Results

Home Forums Support [Support request] Site Search Pulling Back Unexpected Results

Home Forums Support Site Search Pulling Back Unexpected Results

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2580317
    MMS

    Hi, From the home page or any post/page on my site https://makemesustainable.com the search function (In the menu top right) pulls back the relevant page(s) but also for some searches also brings back a blank tile with the home page as the result. How can I prevent a search from showing anything other than the correct search results? (See screenshot) In the example screenshot I searched for the partial match ‘Tru’ as in Tru Earth detergent.
    https://imgur.com/a/MSKXqdZ

    #2580357
    David
    Staff
    Customer Support

    Hi there,

    WP search isn’t particularly great, you can filter its results with a PHP Snippet.
    For example, this trys to exact match the search:

    add_action('pre_get_posts', 'my_make_search_exact', 10);
    function my_make_search_exact($query){
    
        if(!is_admin() && $query->is_main_query() && $query->is_search) :
            $query->set('exact', true);
        endif;
    
    }

    Otherwise you may want to consider a dedicated search plugin that has more options to control the filter.

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