I have a same situation as in this link How to upload multiple images on frontend to ACF gallery using update_field.

but the code is not working for me: it does not add any images to acf image gallery.

My code :


if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {

// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) { 
    $title =  $_POST['title'];

} else { 
    echo 'Please enter a title';
if (isset ($_POST['description'])) { 
    $description = $_POST['description']; 
} else { 
    echo 'Please enter the content'; 

// Add the content of the form to $post as an array
$post = array(
    'post_title'    => $title,
    'post_content'  => $description,
    'post_category' => array($_POST['cat']),

    'post_status'   => 'publish',         // Choose: publish, preview, future, etc.
    'post_type'     => 'work'  // Use a custom post type if you want to
$pid = wp_insert_post($post);  // Pass  the value of $post to WordPress the insert function 

if ($_FILES) {

    $i = 0;//this will count the posts
    foreach ($_FILES as $file => $array) {
        if ($i == 0) $set_feature = 1; //if $i ==0 then we are dealing with the first post
        else $set_feature = 0; //if $i!=0 we are not dealing with the first post
        $newupload = insert_attachment($file,$pid, $set_feature);
        echo $i++; //count posts

    if ($_FILES['upload_attachment']){

        $files = array_map('RemapFilesArray',

        $gallery = array();

        foreach ($files as $file)
        { //loop through each file
            $att = my_update_attachment($file,$pid);



$category_filter = array($_POST['cat_filter']);


functions.php is same as above except that my post type here is work.

and my form is :

<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
    <label for="title">Title :</label><br />
    <input class="form-control" type="text" id="title" value="" tabindex="1" size="20" name="title" minlength="5" required />
<div class="form-group">
    <label for="description">Description :</label><br />
    <textarea class="form-control" id="description" tabindex="3" name="description" cols="50" rows="6" minlength="30" required></textarea>
<div class="form-group">
    $args_drop = array(
        'show_option_none'   => 'Category',
        'hide_empty'         => false,
        'include'            => '26, 27, 29, 34, 33',
        'tab_index'          => 3,
        'taxonomy'           => 'category',
<div class="form-group">
    <label for="file">Image :</label>
    <input type="file" name="file" id="file" required><br>
    <input type="file" name="upload_attachments[]">
    <input type="file" name="upload_attachments[]">

<input type="submit" value="Submit" tabindex="6" id="submit" name="submit" />

<input type="hidden" name="post_type" id="post_type" value="domande" />
<input type="hidden" name="action" value="post" />
<?php wp_nonce_field( 'new-post' ); ?>

Read more here: How to upload multiple images on frontend to ACF gallery using update_field? Not working


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: