Home › Forums › Add-ons › Gallery Field › Feature image from first gallery image › Reply To: Feature image from first gallery image
I just created a gallery field simply named “gallery” and added this simple function
add_filter('acf/save_post', 'gallery_to_thumbnail');
function gallery_to_thumbnail($post_id) {
$gallery = get_field('gallery', $post_id, false);
if (!empty($gallery)) {
$image_id = $gallery[0];
set_post_thumbnail($post_id, $image_id);
}
}
This works, the first image in the gallery is set as the featured image when I save as a draft or I when I publish.
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.