Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.