• Resolved modernsoul

    (@modernsoul)


    I want to search for exact word

    I have a website where I have two major categories “Men” and “Women”

    But whenever I search for Men it show product for women too because Women have “men” in it (Wo’men’)

    And I dont want this to happen

    Do we have any solution for this ??

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Marta

    (@martadella)

    Hi @modernsoul,

    Unfortunately, there’s not a good solution to this problem. You can try the following code snippet, but note that it will return search results only if the keyword matches the beginning of the product title. Eg. if you have a product called ‘Men coat’ and the user searches for ‘coat’, the product won’t show up in the search results.

    add_filter( 'posts_search', function ( $search ) {
        if ( defined( 'DGWT_WCAS_AJAX' ) && DGWT_WCAS_AJAX ) {
          $search = str_replace( ".post_title LIKE '%", ".post_title LIKE '", $search );
        }
    
        return $search;
    }, 510 );

    There are 2 ways to add the code to your website:
    1. Open the functions.php file in your Child Theme and add the code at the end
    2. or install the Code Snippets plugin and apply this code as a snippet

    I hope this is helpful!

    Regards,
    Marta

Viewing 1 replies (of 1 total)
  • The topic ‘I want to search for exact word’ is closed to new replies.