Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save version-control/d2b11972071211341506760af7f5a257 to your computer and use it in GitHub Desktop.
Save version-control/d2b11972071211341506760af7f5a257 to your computer and use it in GitHub Desktop.
Wordpress: Gravity Forms List to ACF Repeater post save
<?php
add_action('gform_after_submission', 'gfToAcfListToRepeater', 10, 2);
function gfToAcfListToRepeater($entry, $form)
{
foreach ($form['fields'] as $field) {
if (!($field['type'] == 'post_custom_field' && $field['inputType'] == 'list' && $field['enableColumns'] == true)) {
continue;
}
$id = $field['id'];
$postId = $entry['post_id'];
$acfFields = unserialize($entry[$id]);
$fieldName = $field['postCustomFieldName'];
$count = 0;
foreach ($acfFields as $item) {
foreach ($item as $key => $value) {
$acfKey = str_replace(' ', '_', strtolower($key));
$acfFieldName = $fieldName . '_' . $count . '_' . $acfKey;
update_post_meta($postId, $acfFieldName, $value);
}
$count++;
};
update_post_meta($postId, $fieldName, count($acfFields));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment