Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Questions about plugin setup / features › Reply To: Questions about plugin setup / features
February 25, 2020 at 2:48 pm
#25985
Participant
Thanks, Ernest! The example you provide works great if in the ACF settings the return format is set to ‘Image ID’. In my case it was ‘Image Array’ so I modified the code a bit:
add_filter( 'asp_results', 'asp_get_main_prod_img', 10, 1 );
function asp_get_main_prod_img($results) {
$acf_image_field = 'design_image';
$size = 'medium';
foreach ( $results as $k => &$r ) {
if ( empty($r->image) && function_exists('get_field') ) {
$image_array = get_field( $acf_image_field, $r->id );
if ( count( $image_array ) > 0 && array_key_exists( 'sizes', $image_array ) ) {
$img = $image_array['sizes'][$size];
if ( isset( $img ) && !is_wp_error( $img ) )
$r->image = $img;
}
}
}
return $results;
}
Thank you for the help!