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.
Site URL: hidden Theme version: 8.0.12 WooCommerce version: 5.9Hello,
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
You must be logged in to reply to this topic.Log in/Sign up
One standard license is valid only for 1 project. Running multiple projects on a single license is a copyright violation.