Title: Multiple ACF Gallery Mapping
Last modified: January 19, 2024

---

# Multiple ACF Gallery Mapping

 *  Resolved [jeppner](https://wordpress.org/support/users/jeppner/)
 * (@jeppner)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/multiple-acf-gallery-mapping/)
 * Hi again,
 * I appreciate all of your help! I’ve been using this code, which works great. 
   However, I need to add another ACF gallery field and I’m wondering how I can 
   add both of them in this code.
 * [https://pastebin.com/fTpAkpxk](https://pastebin.com/fTpAkpxk)
 * Slideshow is {upload-1} and Store_Layout is {upload-4}. I’m wondering how I can
   pass both of them in this code and have their images mapped to their respective
   fields?
 * Thank you so much!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/multiple-acf-gallery-mapping/#post-17358619)
 * Hi [@jeppner](https://wordpress.org/support/users/jeppner/)
 * I hope you are doing well,
 * I checked the code and it will require some further changes there.
 * We escalated this to our second-line support to verify if we can find an easy
   way to map more than one upload field.
 * We will keep you posted.
    Best Regards Patrick Freitas
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/multiple-acf-gallery-mapping/#post-17364854)
 * Hi [@jeppner](https://wordpress.org/support/users/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
 *  Thread Starter [jeppner](https://wordpress.org/support/users/jeppner/)
 * (@jeppner)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/multiple-acf-gallery-mapping/#post-17385275)
 * Thank you very much!! I really appreciate it.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Multiple ACF Gallery Mapping’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [jeppner](https://wordpress.org/support/users/jeppner/)
 * Last activity: [2 years, 3 months ago](https://wordpress.org/support/topic/multiple-acf-gallery-mapping/#post-17385275)
 * Status: resolved