Ajax Search Product – adjust to search product, but not descriptions.

This topic has 4 replies, 4 voices, and was last updated 1 years, 3 months ago ago by Rose Tyler

  • Avatar: PB
    PB
    Participant
    March 15, 2022 at 10:53

    Good day,

    Is there a way to not search product descriptions with the Ajax Search Bar?
    eg. if we search boots, then not just boots appear, but the product which has a description saying it can be worn with boots also appears…

    Your assistance is much appreciated.

    Thank you.

    3 Answers
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    March 15, 2022 at 16:50

    Hello,

    There is no option to exclude description from the search. You can try to implement that by additional customization only. For example, you can try to add the below code to child theme functions.php

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

    You can improve that in case you want to change anything else.

    Regards

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

    This works a treat – would be good to understand how to also search Brands for example so that a Brand Name returns results based on Tag.

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    February 26, 2023 at 08:20

    Hello, Websitedude1985,

    Thank you for using our theme. We apologize for the delay in responding.

    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 to one of our upcoming updates.

    Kind Regards,
    8theme team

  • Viewing 4 results - 1 through 4 (of 4 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.