Last active
December 21, 2018 13:43
-
-
Save shanejones/924ad3127ecf474a0d262854f2cb8de0 to your computer and use it in GitHub Desktop.
If you're submitting a form using GForms and populating ACF you'll need ot run this script on save to push the fields into ACF correctly
This file contains 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
/** | |
* Save Form Items to ACF Properly | |
* | |
* | |
*/ | |
function und2_form_resubmit_fields($entry, $form){ | |
$args = array( | |
'post_type' =>'CUSTOM_POST_TYPE', | |
'posts_per_page' => 1 | |
); | |
$recent_posts = wp_get_recent_posts($args); | |
foreach( $recent_posts as $recent ){ | |
$id = $recent['ID']; | |
$field_group_id = 7; // This needs to be the ID of your custom fields | |
$fields = acf_get_fields( $field_group_id ); | |
foreach( $fields as $field ) { | |
$name = $field['name']; | |
update_field($name, get_field( $name, $id) , $id); | |
} | |
} | |
} | |
// Replace XX with your Gravity Forms ID | |
add_action( 'gform_after_submission_XX', 'und2_form_resubmit_fields', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment