Created
March 3, 2018 16:09
-
-
Save New0/8ae5a6be65247f83a89b9dc949e1e352 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Transform data from file field and update gallery custom field for first listing | |
| * | |
| */ | |
| add_action( 'caldera_forms_submit_complete', function( $form, $referrer, $process_id, $entryid ) { | |
| if( 'CF5a96a2f82ed78' === $form[ 'ID' ] ) { | |
| //change your field ID here | |
| $imgs = Caldera_Forms::get_field_data( 'fld_1166289', $form ); | |
| $attachments_array = array(); | |
| if( !empty($imgs) ) { | |
| foreach( $imgs as $img_url ){ | |
| $img_id = get_attachment_id( $img_url ); | |
| $attachments_array[] = $img_id; | |
| } | |
| } | |
| //Change the field ID of the hidden field using {post_type:ID} magic tag as value | |
| $pid = Caldera_Forms::get_field_data( 'fld_726404', $form ); | |
| $post_id = Caldera_Forms::do_magic_tags( $pid, $entryid ); | |
| //Update the ACF custom field ID | |
| if( !empty( $attachments_array ) && !empty( $post_id )) { | |
| update_field( 'field_5a847474875fd', $attachments_array , $post_id ); | |
| } | |
| }else if( 'CF5a85c35a996a2' === $form[ 'ID' ] ) { | |
| //change your field ID here | |
| $imgs = Caldera_Forms::get_field_data( 'fld_1166289', $form ); | |
| $attachments_array = array(); | |
| if( !empty($imgs) ) { | |
| foreach( $imgs as $img_url ){ | |
| $img_id = get_attachment_id( $img_url ); | |
| $attachments_array[] = $img_id; | |
| } | |
| } | |
| //Change the field ID of the hidden field using {post_type:ID} magic tag as value | |
| $pid = Caldera_Forms::get_field_data( 'fld_726404', $form ); | |
| $post_id = Caldera_Forms::do_magic_tags( $pid, $entryid ); | |
| //Update the ACF custom field ID | |
| if( !empty( $attachments_array ) && !empty( $post_id )) { | |
| update_field( 'field_5a847474875fd', $attachments_array , $post_id ); | |
| } | |
| } | |
| }, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment