Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Category Images in Search Results Not Showing? › Reply To: Category Images in Search Results Not Showing?
March 20, 2015 at 1:54 pm
#4290
Hi!
Yes it is actually. The search can’t show the term images, as there is no such thing by default in wordpress.
However it is possible to add a few lines of code to your themes functions.php file, which will try to parse images for woocommerce terms:
add_filter('asp_results', 'asp_get_woo_term_image');
function asp_get_woo_term_image($results) {
foreach($results as $k => $result) {
if ($result->content_type != 'term') continue;
if (function_exists('get_woocommerce_term_meta') && empty($result->image)) {
$thumbnail_id = get_woocommerce_term_meta( $result->id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if (!empty($image))
$results[$k]->image = $image;
}
}
return $results;
}
This filtering function will parse through the results, and if it finds a woocommerce term image, it will attach it to the actual result. This solution is update ready, since you do not need to modify the search code.
Best,Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)



