Export ACF Flexible Content Fields to CSV or XML

Export ACF Flexible Content Fields to CSV or XML

Flexible Content fields in ACF are automatically detected by WP All Export and added to the ACF section in Available Data.

ACF Flexible Content fields enable a simple block-based editor that allows using layouts and subfields to organize the data. Similar to a Repeater field, any field can be added to a Flexible Content field as a child.

This Flexible Content field has 1 layout that contains 3 subfields, a Text field, an Image field, and a Color Picker field:

When more layouts are added, each exports its own set of columns. The above field exports the following:

Flexible Content__0_text: Exports the string from the text field.Flexible Content__0_image: Exports the URL of the added image.Flexible Content__0_color: Exports the HEX code selected in the color picker.

Here's what that ACF export file looks like:

Export ACF Google Map Fields to CSV or XML

Export ACF Google Map Fields to CSV or XML

Google Map fields in Advanced Custom Fields are automatically detected by WP All Export and added to the ACF section in Available Data.

The ACF Google Map field stores an address, that is then rendered into a map on the frontend. For example:

When exported, this field generates the following export columns:

_address: Exports a string of text with the inserted address. Example: 123, Foo Bar Street, Melbourne, Victoria, 3000, Australia._lat: Exports the latitude of the inserted address. Example: -37.8156542._lng: Exports the longitude of the inserted address. Example: 144.9608007.

Here's how it looks in an export file generated by WP All Export:

Export ACF Media Fields to CSV or XML

Export ACF Media Fields to CSV or XML

ACF fields are automatically detected by WP All Export. To customize your export file, select fields from Available Data › ACF and drag and drop them into the export editor.

The following ACF media fields can be exported: Image, File, Wysiwyg Editor, oEmbed, and Gallery. Here's more information on each field:

Image: Exports the URL to the image. File: Exports the URL to the file. Wysiwyg Editor: Exports the text added to this editor field, exports as plain text.oEmbed: This field provides an interactive component for embedding videos, images, tweets, audio, and other content; it exports an URL to the embedded resource.Gallery: Exports the URLs to the images within the gallery field.

WP All Export treats all ACF media fields in the same way. Image fields export the URL to the image or file. Multiple images or files in a single field will be separated by the pipe ( | ) character.

Export ACF Picker Fields to CSV or XML

Export ACF Picker Fields to CSV or XML

WP All Export detects all ACF fields in the posts you're exporting. To customize your export file, drag fields from the Available Data › ACF section and drop them into the editor on the left.

The following ACF picker fields are available to be exported: Date Picker, Date Time Picker, Time Picker, and Color Picker. Here's more on each field, along with an example of what's exported:

Date Picker: Exports the date in the format d/m/Y, example: 07/05/2021.Date Time Picker: Exports the date and time in the format d/m/Y g:i a, example: 21/05/2021 7:06 am.Time Picker: Exports the time in the format g:i a, example: 3:03 am.Color Picker: Exports the color in its HEX color code, example: #8224e3.

Export ACF Relational Fields to CSV or XML

Export ACF Relational Fields to CSV or XML

All available ACF relational fields are automatically detected by WP All Export and added to the ACF section in Available Data.

The following ACF relational fields are available for export: Link, Post Object, Page Link, Relationship, and User. Here's more on each field:

Link: This field allows to select or define a link (URL, title, target) via the WordPress link popup. Exports the link data separated in the fields Link_title, Link_url, and Link_target (if defined). Post Object: This field enables a drop-down list to select posts, pages, or custom post types. Exports the slug of the selected item.Page Link: Similar to the Post Object field, but also allows selecting archive pages. Exports the full URL to the selected item.Relationship: This field stores relationships between posts, pages, or custom post types. Exports the name of the selected items. User: This field allows the selection of a user account. Exports the email address associated with the selected user.

Multiples values exported within the same field are separated by a pipe ( | ) character.

Export ACF Repeater and Group Fields to CSV or XML

Export ACF Repeater and Group Fields to CSV or XML

ACF Repeater and ACF Group fields are automatically detected by WP All Export and added to the ACF section in Available Data.

Exporting ACF Repeater Fields

The ACF Repeater field allows content to be added as a set of subfields, like slides, team members, etc. Any ACF field can be included as the child of a repeater field. This field acts as a parent to a set of subfields that can be repeated again and again.

For example, this repeater field contains a number field and a text field:

During export, repeater fields add a column for each field that it contains. Following the previous example, this ACF repeater field would export:

A Repeater_number column that contains all repeated numbers separated by a pipe ( | ) character.A Repeater_text column that contains all repeated text strings separated by a pipe ( | ) character.

Here's what that ACF export file looks like:

Exporting ACF Group Fields

The ACF Group field acts as a parent, with grouped fields acting as child items. The parent group field does not contain any data but rather acts as a container for other fields. It is primarily used to organize the ACF user interface.

For example, this ACF group field contains a text field and an image field:

The ACF group field adds an export column for each field that it contains. Following the previous example, this ACF group field exports:

A Group_text column that contains the inserted text string.A Group_image column that contains the URL to the selected image.

Here's what that ACF export file looks like:

Add Exported WordPress Data to Google Sheets using Zapier

Add Exported WordPress Data to Google Sheets using Zapier

Zapier can be used to send details of the export data towards Google Sheets. Connect Zapier to WP All Export and create the required trigger and action. The trigger would execute whenever a new export is found. The action would be sending the export information to Google Sheets.

Trigger: New Export File in WP All Export Pro

First, connect to Zapier and set up the required trigger: https://www.wpallimport.com/documentation/external-app-integration/.

Action: Create Spreadsheet Row in Google Sheets

Choose App & Event

Zapier will prompt to create an action once the trigger is done.

Select Google Sheets as the app and Create Spreadsheet Row as the event, then click Continue.

Choose Account

Select the Google Sheets account to use. If there's no account added, select + Connect a new account from the dropdown list and follow the steps.

Once an account has been selected, click Continue.

Set up action

This section allows configuring in which spreadsheet and worksheet the information will be added.

The following can be configured:

Drive: The Google Drive where the spreadsheet resides. The personal Google Drive is used if nothing is selected. Spreadsheet: Select which spreadsheet should be used by Zapier.Worksheet: Select which worksheet within the spreadsheet should be the data added to.

Once those fields have been selected, Zapier will load headers from the worksheet and allow to select which data is added into those columns. If there are no headers in the worksheet, Zapier will ask to set up the spreadsheet.

The following data can be added to the spreadsheet:

Export NameExport File URLExport Last Run DateRecords ExportedFile NameExport Created DateStatus CodeWebsite URLFile TypePost Types ExportedStatus MessageExport IDExport Trigger Type

Only details from the export can be added to the spreadsheet. Filling the Google Sheet rows with the data from the exported file is not possible with this integration. If that's the desired result, the Google Drive integration should be used instead.

Test action

Once the action has been configured, Zapier will attempt to test it. Select Skip Test to avoid this step.

Otherwise, click Test & Continue to check everything is working.

Once the test is successful, the zap can be enabled by clicking on Turn on Zap.

Best Practices

Best Practices

1. Follow an Object-Oriented design pattern.

You should use a singleton to ensure that your add-on works properly with WP All Import's WP-CLI integration. A singleton is a class that is limited to a single instance.

Example - ensuring a class has only a single instance

static public function get_instance() {
if ( self::$instance == NULL ) {
self::$instance = new self();
}
return self::$instance;
}

Be sure to instantiate the Rapid Add-On when the class is constructed:

$this->add_on = new RapidAddon( 'Yoast SEO Add-On', 'yoast_seo_add_on' );

Here's an overview showing how it all fits together:

/*
Plugin Name: WP All Import Yoast SEO Add-On
Description: A complete example add-on for importing data to certain Yoast SEO fields.
Version: 1.0
Author: WP All Import
*/

include "rapid-addon.php";

final class Yoast_SEO_Add_On {

protected static $instance;

protected $add_on;

static public function get_instance() {
if ( self::$instance == NULL ) {
self::$instance = new self();
}
return self::$instance;
}

protected function __construct() {

// Define the add-on
$this->add_on = new RapidAddon( 'Yoast SEO Add-On', 'yoast_seo_add_on' );

// Add UI elements to the import template
$this->add_on->add_field( 'yoast_wpseo_title', 'SEO Title', 'text' );

// This tells the add-on API which method to call
// for processing imported data.
$this->add_on->set_import_function( [ $this, 'import' ] );

// This registers the method that will be called
// to run the add-on.
add_action( 'init', [ $this, 'init' ] );
}

// Tell the add-on to run, add conditional statements as needed.
public function init() {

$this->add_on->run();

}

// Add the code that will actually save the imported data here.
public function import( $post_id, $data, $import_options ) {

}
}

Yoast_SEO_Add_On::get_instance();

2. Make the add-on run only when necessary.

Your add-on should only run when the user is importing to the theme or post types supported by your add-on.

Otherwise, your add-on』s import function would save data in the database when the user is doing an import that isn』t making use of your add-on.

Specify when your add-on runs using the run function.

This code is placed in the 'init' method as shown in section 1 above.

Example A – only when certain plugins are active

// This approach is needed when you need one OR another plugin active.
if ( function_exists('is_plugin_active') ) {
// Only run this add-on if the free or pro version of the Yoast plugin is active.
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) || is_plugin_active( 'wordpress-seo-premium/wp-seo-premium.php' ) ) {
$this->add_on->run();
}
}

// This approach works when you need one or more plugins active at the same time.
// Only run this add-on if BOTH the premium version of the Yoast plugin and WP All Export are active.
$this->add_on->run(array(
'plugins' => array(
'wordpress-seo-premium/wp-seo-premium.php',
'wp-all-export/wp-all-export.php'
)
));

}

Example B – only when importing to 「listing」 Custom Post Type

$this->add_on->run(
array(
"post_types" => array( "listing" ),
)
);

Example C – only when 「Twenty Fourteen」 OR 「Twenty Fifteen」 themes are activated

$this->add_on->run(
array(
"themes" => array( "Twenty Fourteen", "Twenty Fifteen" )
)
);

Example D – only when importing to 「post」 OR 「page」 Custom Post Type AND when 「Max Estate」 theme is activated AND when the "Max Estate Helper" plugin is activated

$this->add_on->run(
array(
"themes" => array( "Max Estate" ),
"post_types" => array( "post", "page" ),
"plugins" => array( "Max Estate Helper" )
)
);

Example E – run the add-on always

$this->add_on->run();

3. Make the add-on respect the user』s 「Choose which data to update…」 Import Settings.

On future runs of the same import, users can choose to not update Custom Fields, Images, and more.

Choose which data to update Add-On

The rapid add-on API supports checking if Custom Fields or images should be updated.

To do that, use the following methods. They should be placed in the 'import' method as shown in section 1 above.

Use can_update_meta to see if a Custom Field should be updated:

if ( $this->add_on->can_update_meta( '_yoast_wpseo_title', $import_options ) ) {
// Update the field if the user has allowed it in the import settings.
update_post_meta( $post_id, '_yoast_wpseo_title', $data['yoast_wpseo_title'] );
}

Use can_update_image to check of the 「Images」 box is checked:

if ( $this->add_on->can_update_image( $import_options ) ) {
// Retrieve the imported image's URL if images are set to be updated.
$image_url = wp_get_attachment_url( $data['yoast_wpseo_opengraph-image']['attachment_id'] );

// Save that image URL to our custom field.
update_post_meta( $post_id, '_yoast_wpseo_opengraph-image', $image_url );
}

There are more options in the Choose which data to update section, but they are rarely used by add-ons. These options are stored in the $import_options variable, which is passed to the registered import function. If your add-on does advanced things like changing parent posts, menu orders, etc. and you want to support these options, the settings you need to check are stored inside $import_options.

Please note can_update_image only tells you if the Images box is checked, it doesn』t tell you the settings. If you care, read it from $import_options.

4. Warn the user to install WP All Import.

You can display a dismissible notice warning the user to install WP All Import to use your add-on.

$this->add_on->admin_notice();

Customize the notice text by passing a string to admin_notice(), i.e.

$this->add_on->admin_notice(
'The Yoast WordPress SEO Add-On requires WP All Import Free and the Yoast WordPress SEO plugin.'
);

Add conditions for displaying the admin notice:

$this->add_on->admin_notice(
// Provide the notice text here.
"This Add-On requires WP All Import, the WP All Export Plugin and Twenty Fifteen theme.",
// This array should contain all of your conditions.
array(
// Multiple themes and plugins can be required.
"themes" => array( "Twenty Fifteen" ),
"plugins" => array( "wp-all-export/wp-all-export.php" )
)
);

5. Use tooltips when necessary to explain fields to users.

The fifth parameter of the add_field() function can take a string that will be used as a tooltip for the field. This will work for any of the field types.

$this->add_on->add_field(
// Field slug.
'property_price',
// Field display name.
'Price',
// Field type.
'text',
// Used for nested fields.
null,
// Set your tooltip text here.
'Numbers only, no symbols'
);

6. Add entries to the import log.

The log() function must be placed within the import function.

// Ensure it's either a new record or the settings allow updating images.
if ( empty( $article['ID'] ) || $this->add_on->can_update_image( $import_options ) ) {

// Retrieve the URL for our image.
$image_url = wp_get_attachment_url( $data['yoast_wpseo_opengraph-image']['attachment_id'] );

// Save our image URL as required by Yoast.
update_post_meta( $post_id, '_yoast_wpseo_opengraph-image', $image_url );

}

7. Disable the default images section if it』s not being used.

This should be placed within the add-on's constructor.

$this->add_on->disable_default_images();

Related

Overview

A Complete Add-On

A Complete Add-On To Use As A Starting Point

A Complete Add-On To Use As A Starting Point

Use this add-on for importing to Yoast as a starting point for your own add-on. It provides a real-world example of how all of the add-on fields work together with WP All Import. No need to start from scratch, fork this example and modify it to your needs.

Here』s the complete add-on: https://github.com/soflyy/wp-all-import-example-addon

Here's the direct link to the .zip archive that you can install in WordPress: https://github.com/soflyy/wp-all-import-example-addon/archive/master.zip

Once you activate the add-on, you』ll be prompted to install WP All Import if it's not already installed and active on your site.

The add-on is for importing to various fields in Yoast WordPress SEO, so to see the result of what the add-on does you』ll need that plugin installed as well.

Do a new import with WP All Import Import (Download example-yoast-data.csv) – you』ll see the add-on show up in Step 3 of WP All Import Import.

Related

Overview

Best Practices

Image Fields

Image Fields

Importing Single Images

Image fields allow the user to specify a single image URL or file path.

Rapid Add-On will automatically place the specified image in the Media Library and pass the ID of the media to the registered import function.

These fields should all be defined in your add-on's constructor.

$this->add_on->add_field( 'property_featured_img', 'Property Featured Image', 'image' );

Add-On Single Image Field

Your add-on』s import method will be passed the image data as an array. The ID of the image will be passed as the 「attachment_id」 array key.

Here』s how to set the Featured Image/Post Thumbnail to the specified image.

This example assumes the field slug specified in add_field is 「property_featured_img」.

public function import( $post_id, $data, $import_options ) {
$attachment_id = $data['property_featured_img']['attachment_id'];
set_post_thumbnail( $post_id, $attachment_id );
}

Importing Multiple Images

You can add entire image sections, with all of the settings and features that the default image section has, using the import_images() function.

$this->add_on->import_images( 'property_images', 'Property Images', 'images', [ $this, 'property_images' ]);

Add-On Multiple Images

This will call the property_images() method every time an image is imported. There you can process the image references as needed.

public function property_images( $post_id, $attachment_id, $image_filepath, $import_options ) {

// Retrieve previously stored image references.
$urls = get_post_meta($post_id, 'property_gallery', true);

// Add the attachment ID to the list as our example requires.
$urls[] = $attachment_id;

// Create a comma delimited list for our example field.
$new_urls = implode(',', $urls);

// Save the updated list of attachment IDs.
update_post_meta( $post_id, 'property_gallery', $new_urls );

}

Some themes allow users to upload files like PDFs. You can enable another section, identical to the default image section, except that it will allow any file type to be imported and attached to the post.

$this->add_on->import_files( 'property_attachments', 'Property Attachments', [ $this, 'property_attachments' ] );

Related

Add-On Structure

Text Fields

Radio Fields

Nested Fields