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

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in 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.
    in reply to: Questions about plugin setup / features #25901
    dmitry01dmitry01
    Participant

    1. Thanks!
    2. Thanks, I saw it and it works, but as far as I understand this is not about indexing, products hidden from the catalog will still be included into index. This is not important actually as the current solution works fine.
    3. Those images are uploaded with ACF in my case and have the [‘sizes’] array with all image sizes. Maybe there is a way to access this array and assign (hard-code) the medium size to images of a specific custom post type?

Viewing 2 posts - 1 through 2 (of 2 total)