Hey Everyone,
For a website, we are using gravity forms in combination with ACF (pro).
When a commit is made (using the gravity form) it will generate a custom POST_TYPE.
I have written an exporter for the data of those post types.
I can export almost all data except data from a group. The weird thing is when I go to the specific post type and save (update) it I have no problem exporting it.
When we look in the database and update the post there are a lot more postmeta then posted with gravity forms.
Script to generate fields
acf_add_local_field_group(array(
'key' => 'group_xxx',
'title' => 'Group',
'fields' => array(
array(
'key' => 'field_xxxx',
'label' => 'Band members',
'name' => 'band_members',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => '',
'sub_fields' => array(
array(
'key' => 'field_xxx',
'label' => 'Name',
'name' => 'name',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_xxxxx',
'label' => 'Surname',
'name' => 'surname',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_xxxx',
'label' => 'Instrument',
'name' => 'instrument',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
),
Script to export data (part of it)
$field_groups = acf_get_field_groups();
if (is_admin()) {
if (isset($_GET['export_showcases'])) {
$showcases = new \WP_Query(array(
'post_type' => 'showcase',
'posts_per_page' => -1,
));
if ($showcases->have_posts()) {
while ($showcases->have_posts()) {
$showcases->the_post();
$exportArray['bandname'] = get_the_title();
$exportArray['genre'] = implode(", ", wp_get_post_terms(get_the_id(), 'showcase_genre', array("fields" => "names")));
$bandMembers = null;
if (is_array(get_field('band_members'))) {
foreach (get_field('band_members') as $key => $bandMember) {
$bandMembers .= $bandMember['name'] . ' ' . $bandMember['surname'] . ': ' . $bandMember['instrument'];
if ($key + 1 < count(get_field('band_members'))) {
$bandMembers .= ', ';
}
}
}
$exportArray['bandmembers'] = $bandMembers;
$exportArray['longlist'] = get_post_meta(get_the_id(), 'longlist', true);
$exportArray['shortlist'] = get_post_meta(get_the_id(), 'shortlist', true);
$exportArray['personal_interest'] = wp_count_comments(get_the_id())->total_comments;
$exportArray['management_name'] = get_field('management_name');
$exportArray['contact_name'] = get_field('contact_name');
$exportArray['contact_surname'] = get_field('contact_surname');
$exportArray['contact_address'] = get_field('contact_address');
$exportArray['contact_zipcode'] = get_field('contact_zipcode');
$exportArray['contact_town'] = get_field('contact_town');
$exportArray['contact_email'] = get_field('contact_email');
$exportArray['contact_phone'] = get_field('contact_phone');
$exportData[] = $exportArray;
}
}
The topic ‘Exporting data from ACF (Pro) added using gravity forms’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.