Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › show a taxonomy image in results › Reply To: show a taxonomy image in results
Hi!
Well, it is definitely possible, but since by default wordpress does not support images to taxonomies, some themes/plugins use different methods to that.
I checked the taxonomy editor page, I suspect it uses a term meta to store the image URL, but I am not sure. From the page source, I am guessing, that the meta field name is “image”, and it probably contains the URL itself. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter('asp_results', 'asp_get_term_image_by_meta');
function asp_get_term_image_by_meta($results) {
$key = "image"; // Image term meta key
foreach($results as $k=>&$r){
if ( $r->content_type == 'term' && empty($r->image) ) {
$value = get_term_meta( $r->id, $key, true );
if ( !empty($value) ) {
// Is this an image attachment ID
if ( is_numeric($value) ) {
$img = wp_get_attachment_image_src( $value, 'thumbnail');
if ( isset($img[0]) )
$r->image = $img[0];
} else {
// Probably the image URL
$r->image = $value;
}
}
}
}
return $results;
}
This may not work though, as I am only guessing here. If it does not work, can you please ask the theme author about this? If he can tell, how to get the image URL by the taxonomy term ID, then I can modify this code to the correct solution.