My HTML form allows users to select any number of images to be uploaded to a custom post type. I've created a repeater field in ACF called 'images', of 'image' objects.
How do I save the uploaded images into that repeater field?
This is what I currently have:
$files = $_FILES['file'];
$image_number = 1;
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
$uploaded_file = wp_handle_upload($file, array('test_form' => FALSE));
update_sub_field( array('images', $image_number++, 'image'), $uploaded_file, $post_id);
}
}
But the images aren't saved. Any help appreciated, thanks!