I’ve added a math problem to the registration form for now. Any other ideas would be appreciated. Thanks!
John Huebner’s reply and this post sent me into the right direction:
https://support.advancedcustomfields.com/forums/topic/acf_form-attachment-to-media-gallery/
Modified it for gallery field.
function my_save_post( $post_id ) {
//attachment to media gallery
$my_files = get_field('my_gallery', $post_id);
if($my_files){
foreach( $my_files as $my_file ):
$file_id = $my_file['ID'];
$post_to_update = array(
'ID' => $file_id,
'post_parent' => $post_id
);
wp_update_post( $post_to_update );
endforeach;
}
}
add_action('acf/save_post', 'my_save_post', 15);
I tried:
update_post_meta($post_id, ‘_thumbnail_id’, $image_id);
It sets my image as featured image, and it displays correctly, but the image is still unattached to the post, therefor not in the media uploaded to post list.
I found this function, wp_media_attach_action(). Not sure how to use it though.
Thanks,
The post was saved correctly, so I end up saving the post first, and then send the email, instead of save the post and send email at the same time. This way I got the correct values in the email.