Hi @jeppner
We’ve got response from our second-line support and they’ve suggested an updated version of the code. Would you give it a try, please?
add_action( 'forminator_post_data_field_post_saved', 'wpmudev_update_post_acf_uploads', 10, 4 );
function wpmudev_update_post_acf_uploads( $post_id, $field, $data, $cls ) {
$submitted_data = Forminator_CForm_Front_Action::$prepared_data;
$acf_fields = array( 'slideshow', 'store_layout' ); // set your ACF gallery fields names.
$form_ids = array( 6, 7269 ); // set your form IDs.
if ( ! in_array( $submitted_data['form_id'], $form_ids ) ) {
return;
}
$acf_field = '';
$upload_field = '';
if ( isset( $submitted_data['postdata-1']['post-custom'] ) ) {
foreach ( $submitted_data['postdata-1']['post-custom'] as $pkey => $pval ) {
if ( ( in_array( $pval['key'], $acf_fields ) ) && ( strpos( $pval['value'], 'upload') !== false ) ) {
$img_ids = array();
$acf_field = $pval['key'];
$upload_field = str_replace( "}", "", str_replace( "{", "", $pval['value'] ) );
foreach ( $submitted_data[$upload_field]['file']['file_url'] as $ikey => $iurl ) {
$img_ids[] = attachment_url_to_postid( $iurl );
}
if ( ! empty( $img_ids ) ) {
update_field( $acf_field, $img_ids, $post_id);
}
}
}
}
}
Note: in these two lines you may need to adjust your ACF field names and form IDs
$acf_fields = array( 'slideshow', 'store_layout' ); // set your ACF gallery fields names.
$form_ids = array( 6, 7269 ); // set your form IDs.
Kind regards,
Adam