This topic has 4 replies, 4 voices, and was last updated 1 years, 9 months ago ago by Rose Tyler
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.
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
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.
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
You must be logged in to reply to this topic.Log in/Sign up