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);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.