Skip to content

Instantly share code, notes, and snippets.

@shanejones
Last active December 21, 2018 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanejones/924ad3127ecf474a0d262854f2cb8de0 to your computer and use it in GitHub Desktop.
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
/**
* 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