Site logo

[Support request] Search bar functionality

Home Forums Support [Support request] Search bar functionality

Home Forums Support Search bar functionality

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2576818
    Harsha Kiran Gudibandi

    Hey again. I have something that’s not really a problem, it’s just a matter of preference. When I use the search bar to search for ‘law’, posts with the words containing “law” like ‘lawn’ show up. Is there a way I can fix this to get only exact matches? https://whattobecome.com/?s=law

    Thanks in advance

    #2576863
    David
    Staff
    Customer Support

    Hi there,

    you can try adding this PHP Snippet:

    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;
    
    }

    It should make the search query match words exactly.

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