2

I'm trying to pre-populate the File upload field with files already submitted previously, using ACF PRO and ACF Frontend Form.

So far, I am able to retrieve a list of files that was previously uploaded but can't seem to figure out a way to set it in the file upload frontend.

The File upload field lives inside a Repeater group.

In the functions.php: I added a load_value with key set to the repeater group: add_filter('acf/load_value/key=field_5e80ed8f4516b', 'my_acf_set_file_list', 10, 3);

Then in the function I attempted to set the $value to be an array of file urls.

'field_5e80edf14516c' is the key for the File field.

function my_acf_set_file_list( $value, $post_id, $field ){
    $order_id = $_GET['order'];
    $value = array();
    // get existing files
    $existing_files = get_post_meta( $order_id, 'file', true);
    if ( !empty( $existing_files ) ) {
        $i = 0;
        foreach ( $existing_files as $file ) {
            $value[$i]['field_5e80edf14516c'] = $file;
            // also tried
            // $value[$i]['field_5e80edf14516c'] = $file['file'];
        }
    }
    return $value;
}

The problem is in the frontend form, there seems to be no change at all. No file was pre-populated. I'm pretty sure I didn't get the array structure correct, but I've searched all over and cannot find any related information.

The post data for when I upload existing files seem to indicate the attachment ID is used. But I'm not sure what is the row-0 and other id 5ebf042bba99f?

acf[field_5e80ed8f4516b]: 
acf[field_5e80ed8f4516b][row-0][field_5e80edf14516c]: 381
acf[field_5e80ed8f4516b][5ebf042bba99f][field_5e80edf14516c]: 381
acf[field_5e80ed8f4516b][5ebf042cba9a0][field_5e80edf14516c]: 401

Thanks in advance!

chenZ
  • 21
  • 2

0 Answers0