This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Questions about plugin setup / features

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Questions about plugin setup / features Reply To: Questions about plugin setup / features

#25985
dmitry01dmitry01
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!

  • This reply was modified 6 years, 3 months ago by dmitry01dmitry01.
  • This reply was modified 6 years, 3 months ago by dmitry01dmitry01.