Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Image source settings › Reply To: Image source settings
May 27, 2019 at 9:04 am
#22864
Keymaster
Hi!
The issue is related to a custom code you have to get the taxonomy images within your theme functions.php file. Since the plugin does not find the image internally, it uses the default image. Then the custom code is executed, but since there is already an image, it is not in use. Try replacing it with this variation instead:
add_filter( "asp_results", "asp_acf_cf_image", 10, 1 );
function asp_acf_cf_image( $results ) {
// Change this to the ACF custom field name
$image_field = 'search_image';
$default = 'https://domain.com/wp-content/plugins/ajax-search-pro/img/default.jpg';
// ----------------------------------------------
// --- Do not change anything below this line ---
// ----------------------------------------------
foreach ( $results as $k => &$r ) {
if ( ( empty($r->image) || $r->image == $default ) && $r->content_type == 'term' ) {
$img = get_field($image_field, $r->taxonomy . '_'.$r->id);
if ( !empty($img) )
$r->image = str_replace("'", "%27", $img);
}
}
return $results;
}