Support

Account

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.