• Resolved Jess

    (@jeppner)


    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

    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

    (@wpmudevsupport12)

    Hi @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 Williams – WPMU DEV Support

    (@wpmudev-support8)

    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

    Thread Starter Jess

    (@jeppner)

    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.