Site logo

Archived topic

Site Search Pulling Back Unexpected Results

1 reply · Started by MMS on March 24, 2023

Viewing posts 1–2 of 2

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

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.

This archived topic is closed to new replies.