Home › Forums › Add-ons › Gallery Field › add thumbnail_id to gallery id db table › Reply To: add thumbnail_id to gallery id db table
A gallery field stores an array of post ID’s. To add an image you first need to get the value and add the new ID value to it.
$gallery = get_field('gallery', get_the_ID(), false); // get unformatted value
if (empty($gallery)) {
$gallery = array();
}
$gallery[] = get_post_thumbnail_id(get_the_ID());
update_field('gallery', $gallery, get_the_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.