Home Forums General Issues Update Gallery Field Reply To: Update Gallery Field

  • Are you using media_sideload_image() to import the image to the media folder? It is not clear that this is the case. The image most be in the DB to add it to an ACF field.

    A gallery field holds an array of attachment IDs.

    // return array of current image IDs
    $gallery = get_field($selector, $post_id, false);
    if (!$gallery) {
      $gallery = array();
    $gallery[] = $new_attachment_id;
    update_field($selector, $gallery, $post_id);