I want to upload images in the ACF repeater. That repeater means the gallery of page. Point is to create post in custom post type using add_post_meta() method.
Here I have the form :
<input type="file" class="custom-file-input" id="customFile" multiple accept="image/x-png,image/gif,image/jpeg" name="gallery[]">
Form method is POST and form have enctype="multipart/form-data"
attribute.
In the accept file where I need to process request and income:
$estate_gallery = $_FILES['gallery']; //array of images, I have above in input name="gallery[]"
Well, in ACF I have created Repeater of gallery images, to create fields (in my case subfields) I used this example.
$repeater_field = 'repeater'; //with my keys and names
$repeater_key = 'field_5443d4e2dd4e4';
$sub_field = 'sub_field';
$sub_field_key = 'field_5443d4e2dd4e5';
$count = count($values); // here in my case is $estate_gallery
if ($count) {
// the db value stored in the db for a repeater is
// the number if rows in the repeater
add_post_meta($post_id, $repeater_field, $count, true);
add_post_meta($post_id, '_'.$repeater_field, $repeater_key, true);
for ($i=0; $i<$count; $i++) {
// the actual field name in the DB is a concatenation of
// the repeater field name, the index of the current row
// and the sub field name, with underscores added
$sub_field_name = $repeater_field.'_'.$i.'_'.$sub_field;
add_post_meta($post_id, $sub_field_name, $values[$i], false);
add_post_meta($post_id, '_'.$sub_field_name, $sub_field_key, false);
}
}
And that works very well, numbers of subfields in the repeater are equal to image number in input.
But I can't see images uploaded...
I suppose images from input must be uploaded in media and connected with repeater field? How do that?
Thanks. o/