Support

Account

Home Forums General Issues Image array not returned with get_field

Solving

Image array not returned with get_field

  • I’ve got an image field set up to return the image array and I use update_field with the $attachment_id e.g.:

    update_field(‘photo_image’, $attachment_id, $post_id);

    When I then try to retrieve this using:

    $image = get_field(‘photo_image’, $post_id);

    It returns the attachment id and not the image array. If I update the post via WordPress, subsequent calls to get_field returns the image array but only when I update the post via WordPress.

    I’m on 5.1.8. I have tried 5.1.9.1 as well but the same issue occurs.

  • I think this is expected behavior. Updating the way the field returns data would require you to update the field in the database by updating the post.

  • But I am already updating the field in the database using update_field().

    Are you suggesting that it’s okay for get_field() to return different results for the same field before and after updating a post in wp-admin?

  • you use update_field(‘photo_image’, $attachment_id, $post_id);
    what is the value of $attachment_id that you try to import?
    do you know if $attachment_id has to be an array, inside a array, or a single value?
    i can imagine that it has to be an array or inside a a array structure but i am not sure.

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

The topic ‘Image array not returned with get_field’ is closed to new replies.