'Wordpress ACF Pro Gallery images from API

I am new and learning APIs with ACF but stuck in the middle of nowhere. From the API connection, I loaded the 1st image to WP post type featured image.

$image =  $item->{"photos"}[0]->{"thumbnails"}->{"thumb_1024"};

Then

$img = media_sideload_image( $image, $post_id);
    $img = explode("'",$img)[1];
    $attId = attachment_url_to_postid($img);
    set_post_thumbnail( $post_id, $attId );

It works. However, I created a ACF Pro gallery block and trying to load all the images to there, but not working. I tried this

for ($i = 0; $i < count($image); $i++ ) {
                $image =  $item->{"photos"}[$i]->{"thumbnails"}->{"thumb_1024"};
            }

Then

update_field("acf_gallery",$attId, $post_id);

ACFpro gallery block's field is "acf_gallery". Not sure how to fix this, hope can get some help. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source