Skip Navigation

[Resolved] Export custom post type data and related repeatable field group data

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to export information from a repeatable field group (RFG) into a CSV format.

Solution: A plugin like WP All Export can export RFG information if you add a bit of custom code in the export configurations.

Relevant Documentation: See the examples and screenshots below.

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 3 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#2046083

Hi,
I am having this same problem https://toolset.com/forums/topic/how-to-export-custom-post-type-data-and-related-repeatable-field-group-data/ to export some CPT and their respective RFG.
Is this possible today with WP All Export + Toolset?
Or maybe at least get at RFG export csv the URL of the CPT it's related to?

#2046411
1-select-rfg-and-customize-export.png
2-add-custom-fields.png
3-create-custom-guid-field.png
4-after-create-custom-guid-field.png
5-csv.png

The All Export Pro plugin can export RFG contents in a CSV file. I'm not sure how to combine the RFG and the parent post exports in a single file, but I can show you how to export the RFGs separate from the parent posts. If you want to import these RFG posts into another site, Toolset's relationships import process expects a column in the CSV file using the column header format _toolset_associations_rfg-slug: https://toolset.com/course-lesson/importing-content-from-csv-with-post-relationships/ Replace rfg-slug with the slug of your RFG. In my example, the RFG slug is book-rfg-1. The importer process expects the parent post's GUID (preferred) or post title in this column. You can use a custom function to export that value, with our post relationships API.

You mentioned you would like the related post's URL, so I can show you functions to access the GUID or the permalink of the parent post. You can add either column, or both columns, depending on your needs.

To get the related post GUID or permalink, you need to use a custom function in the All Export Pro configurations. Here is a custom function example that will help export the parent post's GUID information:

<?php
function rfg_parent_guid($id)
{
  $parent_id = toolset_get_related_post( $id, 'book-rfg-1', 'parent');
  $guid = get_the_guid($parent_id);
  return $guid;
}
?>

Replace book-rfg-1 with the slug of your RFG.

If you want to include the parent post's URL (permalink), a function to export that information would look like this:

<?php
function rfg_parent_permalink($id)
{
  $parent_id = toolset_get_related_post( $id, 'book-rfg-1', 'parent');
  $permalink = get_permalink($parent_id);
  return $permalink;
}
?>

Replace book-rfg-1 with the slug of your RFG.

I'm showing some screenshots of how you can set up a CSV export with a custom column including a value from a custom function in All Export Pro, and the results of this export in a CSV file.
1. Select the RFG as the specific post type
2. Include the post ID, title, content, and any custom fields you want to export from the RFG. I have included two custom fields, book-rfg-1-single-line-1 and book-rfg-1-single-line-2, and also included the field toolset-post-sortorder to preserve the sort order of the RFGs in each post. Next you need to add a custom field to include related post information.
3. Add a new custom field to the export. Use the column header format _toolset_associations_rfg-slug if you want to import these RFGs into another site along with their parent posts, or use any other format you want if you do not plan to import these RFGs into another site. Your new field should export the value returned by a custom function as shown here.
4. You can see the export configurations after adding the _toolset_associations_rfg-slug column/field.
5. Example CSV export results including the parent post's GUID information.