Support

Account

Home Forums General Issues Update Gallery Field

Helping

Update Gallery Field

  • hello
    i am developing a plugin
    i have a image url and with php save that inside upload folder
    how can to update a gallery filed of a post with that image,
    with

    update_field($selector, $value, [$post_id]);
    

    i just can update text value not gallery values

  • 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);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.