This topic has 5 replies, 3 voices, and was last updated 1 years, 9 months ago ago by Tony Rodriguez
Hi XStore support team,
My search results are displaying unrelated products to the search on my website.
How to avoid woocommerce to look for the search in the “product description”?
Thanks in advance for your usual help!
Kind regards,
Leandro.
This works a treat…. (put in Child Theme php)
/**
* Limit search to title
*/
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);
Hello @Leandro,
We suggest that you use the code provided by @websitedude1985 (https://www.8theme.com/reply/347580/) in the functions.php file of your Child Theme and then clear your cache and check back the result.
Best Regards,
8Theme’s Team
Thanks @websitedude1985 and @tony-rodriguez for the replies.
I will try to implement that on my Child Theme.
Is it easy to add tags?
Thank you!
Kind regards,
Leandro.
Hello Leandro,
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 in one of our upcoming updates.
Best Regards,
8Theme’s Team
You must be logged in to reply to this topic.Log in/Sign up