We need XStore AJAX Search by Title Only

This topic has 4 replies, 2 voices, and was last updated 5 months ago ago by Luca Rossi

  • Avatar: owncloud
    owncloud
    Participant
    July 13, 2025 at 12:30

    we want AJAX search finds results only from product titles, not descriptions, in WordPress WooCommerce.
    we are using Ajex header search

    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    July 14, 2025 at 05:41

    Dear @owncloud,

    Can you please try adding this custom code under functions.php file locates in your child theme?

    
    function etheme_search_by_title( $search, $wp_query ) {
        if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
            global $wpdb;
    
            $q = $wp_query->query_vars;
            $n = ! empty( $q['exact'] ) ? '' : '%';
    
            $search = array();
    
            foreach ( ( array ) $q['search_terms'] as $term )
                $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
    
            if ( ! is_user_logged_in() )
                $search[] = "$wpdb->posts.post_password = ''";
    
            $search = ' AND ' . implode( ' AND ', $search );
        }
    
        return $search;
    }
    add_filter( 'posts_search', 'etheme_search_by_title', 100, 2 );
    

    For more information, please take a look at this article: https://stackoverflow.com/a/31904911/2660153.

    Hope it helps!

    Avatar: owncloud
    owncloud
    Participant
    July 14, 2025 at 07:18

    Applied But Not working

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    July 14, 2025 at 08:08

    Hi @owncloud,

    Please sure your XStore child theme is active: https://prnt.sc/l_7aYyk3ORd2.

    Best Regards,
    8Theme’s 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.