we want AJAX search finds results only from product titles, not descriptions, in WordPress WooCommerce.
we are using Ajex header search
This topic has 4 replies, 2 voices, and was last updated 5 months ago ago by Luca Rossi
we want AJAX search finds results only from product titles, not descriptions, in WordPress WooCommerce.
we are using Ajex header search
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!
Applied But Not working
Hi @owncloud,
Please sure your XStore child theme is active: https://prnt.sc/l_7aYyk3ORd2.
Best Regards,
8Theme’s Team
You must be logged in to reply to this topic.Log in/Sign up