Search Result Displaying Unrelated Products

This topic has 5 replies, 3 voices, and was last updated 1 years, 3 months ago ago by Tony Rodriguez

  • Avatar: Leandro
    Leandro
    Participant
    February 21, 2023 at 02:09

    Hi XStore support team,

    My search results are displaying unrelated products to the search on my website.

    How to avoid woocommerce to look for the search in the “product description”?

    Thanks in advance for your usual help!

    Kind regards,

    Leandro.

    4 Answers
    Avatar: websitedude1985
    WebsiteDude
    Participant
    February 21, 2023 at 03:11

    This works a treat…. (put in Child Theme php)

    /**
    * Limit search to title
    */
    function search_by_title_only($search, $wp_query)
    {
    global $wpdb;
    if (empty($search)) {
    return $search; // skip processing – no search term in query
    }
    $q = $wp_query->query_vars;
    $n = !empty($q[‘exact’]) ? ” : ‘%’;
    $search =
    $searchand = ”;
    foreach ((array) $q[‘search_terms’] as $term) {
    $term = esc_sql($wpdb->esc_like($term));
    $search .= “{$searchand}($wpdb->posts.post_title LIKE ‘{$n}{$term}{$n}’)”;
    $searchand = ‘ AND ‘;
    }
    if (!empty($search)) {
    $search = ” AND ({$search}) “;
    if (!is_user_logged_in()) {
    $search .= ” AND ($wpdb->posts.post_password = ”) “;
    }
    }
    return $search;
    }
    add_filter(‘posts_search’, ‘search_by_title_only’, 20, 2);

    Avatar: Tony Rodriguez
    Tony Rodriguez
    Support staff
    February 21, 2023 at 13:37

    Hello @Leandro,

    We suggest that you use the code provided by @websitedude1985 (https://www.8theme.com/reply/347580/) in the functions.php file of your Child Theme and then clear your cache and check back the result.

    Best Regards,
    8Theme’s Team

    Avatar: Leandro
    Leandro
    Participant
    February 22, 2023 at 08:16

    Thanks @websitedude1985 and @tony-rodriguez for the replies.

    I will try to implement that on my Child Theme.

    Is it easy to add tags?

    Thank you!

    Kind regards,

    Leandro.

    Avatar: Tony Rodriguez
    Tony Rodriguez
    Support staff
    February 22, 2023 at 10:28

    Hello Leandro,

    Our theme searches by title, description, SKU, posts, and pages, but does not search by tags, brands, or categories. For more information, please refer to the following link: https://www.8theme.com/topic/include-brands-in-search-results/.

    If you would like to request that this feature be added, you can post your request on our Taskboard at https://www.8theme.com/taskboard/. If it receives enough votes from other customers, our development team will consider adding it in one of our upcoming updates.

    Best Regards,
    8Theme’s Team

  • Viewing 5 results - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.