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 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 Choice Fields to CSV or XML

Export ACF Choice Fields to CSV or XML

The available ACF choice fields would appear under Available Data › ACF. To add a field, drag and drop from right to left:

The following ACF choice fields that can be exported: Select, Checkbox, Radio Button, Button Group, and True/False. Here's more on each field, along with an example of what's exported:

Select: The Select field contains a drop-down list with choices to select fromCheckbox: The Checkbox field contains a list of check-able inputs. Multiple values are separated by a pipe ( | ) character.Radio Button: The Radio Button field contains a list of selectable inputs.Button Group: This field enables a neat UI to select a value.True / False: This field allows selecting a value of either 1 (true) or 0 (false).

WP-CLI

WP-CLI

You may run an import using WP All Import's WP-CLI integration. Imports run with WP-CLI tend to process about 50% faster than those run through the WordPress admin panel.

You can list the imports to find the ID you want to run:

$ wp all-import list

Then, to run an import, you just need to specify the import ID:

$ wp all-import run

Or, if you prefer to run several imports in sequence, a comma-delimited list of import IDs can be specified:

$ wp all-import run ,,

While imports can be run with WP-CLI, you still need to create and edit them in the WordPress admin panel. After saving your import, you can see the import ID on the Manage Imports page, or use the list command above.

Options

A single import ID, or comma delimited list of IDs, to run.

$ wp all-import run 1
$ wp all-import run 1,2,3

[--force-run] A flag to force the import to run even if it's already triggered.

$ wp all-import run 1 --force-run

[--disable-log] A flag to disable the import history log for this run.

$ wp all-import run 1 --disable-log

Add-On Compatibility

In order to be run with WP-CLI, import add-ons must be written using a singleton, a class limited to a single instance. You can read more about this here: https://www.wpallimport.com/documentation/addon-dev/best-practices/

Developer Options For Extending WP All Import

Developer Options For Extending WP All Import

Using custom PHP code with our API and our Add-On API allows developers to extend WP All Import to work with any theme or plugin. Use snippets with our actions or filters to quickly modify how individual data is imported. Need to call a function after import? There's an action for that.

Related

Custom Code

Code Snippets

Action Reference

Add-On API

Using PHP to Extend WP All Import's Functionality

Using PHP to Extend WP All Import's Functionality

Using custom PHP code, you can modify the values in your file to fit the requirements of WooCommerce or other plugins. Use FOREACH loops to retrieve and modify multiple elements in your file. Select only needed file records using custom XPath. And, extend WP All Import using our filters and actions.

Related

IF Statements

FOREACH Loops

Filters & Actions

Custom XPath

Calling PHP Functions In Your Import Configuration

Calling PHP Functions In Your Import Configuration

You can execute any PHP function (native functions, or user-defined functions) from inside virtually any text box (post title, post content, Custom Field values, etc.) of WP All Import. You can even pass values from your data file to the PHP function.

Example 1 – using the native str_replace function to remove commas

Here, we』re using the str_replace function to remove commas from the post title:

[str_replace(",", "", {title[1]})]

string replace example

Note the use of the double quotes instead of single quotes. You must use double quotes when executing PHP functions from within WP All Import. You can』t use single quotes.

Example 2 – custom code in the Function Editor

WP All Import has a built-in code editor where you can write your own custom functions. You can access the Function Editor when editing your import template, or via All Import > Settings in your WordPress dashboard.

The Function Editor makes code editing easy:

Syntax highlightingBuilt-in linting to prevent site-breaking errorsCode only runs during an importWrite and test code on the edit import page using the 「Preview」 feature

As an example, let』s say we are importing WooCommerce products and need to increase the price by 50%, and round it so that it looks nice.

We can do this by writing a custom PHP function to process and return the desired price.

Here』s an example of a function that you could use:

function round_price( $price = null, $multiplier = 1, $nearest = .01, $minus = 0 ) {if ( !empty( $price ) ) {// strip any extra characters from price$price = preg_replace("/[^0-9,.]/", "", $price);// perform calculationsreturn ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; }}

Which can be added directly to the Function Editor on the Edit Import page:

Function Editor Example

Then we call this function in the 「Regular Price」 field provided by our WooCommerce Add-On, where we would customize it based on our needs. We want to set the multiplier to 1.5 so our prices are increased by 50%. We want set the round parameter to 10 so prices will be rounded off to the nearest $10. And finally, we want to set the minus parameter to .01, so we get prices ending in $.99.

[round_price({price[1]},"1.5","10",".01")]

This way, a product with a price of $55 will be imported with a price of $79.99.

Function in import template

You can set the parameters to be whatever you like, or modify the code itself to do something else. Writing code in the Function Editor is easy, fast, and infinitely customizable. Once you click Save Functions you can click the Preview button to see the results, and then modify as needed.

Related

IF Statements

FOREACH Loops

Mapping Values From Your File with IF Statements

Mapping Values From Your File with IF Statements

As WP All Import allows you to use PHP functions on your data, you can create your own custom PHP functions that can be passed values from your data file, and return a certain result based on if/else conditions you set in your function.

Example A – If an element is empty

In this example, we』re checking to see if the element passed is empty or not, and returning a simple text string.

function is_element_empty($element) {
if(empty($element)) {
return "This element is empty.";
} else {
return "This element is not empty!";
}
}

Example B – If an element contains a value

In this example, we』re passing two parameters: the element from the data file that we want to check, and the value we want to search this element for.

function my_contains_function($element, $value_to_search_for) {
if (stripos($element, $value_to_search_for) !== false) {
return $element;
} else {
return;
}
}

If the element passed to this function contains the value to search for, then the element will be returned. Otherwise, an empty result will be returned.

Example C – If one element contains a greater value than another element

In this example, we』re passing two parameters again, this time in the context of comparing two elements that contain prices.

function choose_price_to_return($price1, $price2) {
if ($price1 > $price2) {
return $price1;
} else {
return $price2;
}
}

If the first element passed has a greater value than the second element, the first element will be returned. Otherwise, the second element will be returned.

Further reading:

if statements: http://php.net/manual/en/control-structures.if.phpelse statements: http://php.net/manual/en/control-structures.else.phpelseif statements: http://php.net/manual/en/control-structures.elseif.php

Note: If you』re needing some inspiration for writing your own custom IF/ELSE functions, a good resource to check out is stackoverflow.com, as there are lots of code discussions there.

Related

Inline PHP

FOREACH Loops

Processing and Grouping Multiple Elements with FOREACH Loops

Processing and Grouping Multiple Elements with FOREACH Loops

WP All Import supports a FOREACH syntax that makes it easy to make adjustments to multiple elements from your file at the same time. This is useful when building custom HTML in the Content section, or when preparing other data from your file for fields that require a specific format.

Here's an example showing how to implement a FOREACH loop in WP All Import.

Here's an example XML file that contains some image information – It is assumed the default (/element) was chosen as the XPath in Step 2.

1

My Caption
Another Caption
We will use these for alt text
More text

Here』s an example import template where FOREACH is used to loop through each img element in the above XML.

[FOREACH({images/img})]
{.}
[ENDFOREACH]

Passing {images/img} to the FOREACH means we will loop through each element matching that XPath. To get this XPath, just drag one of the matching elements from the XML tree on the right to the post content box. You』ll get something like {images/img[1]}. Just remove the [1] and you』re good to go.

Inside the FOREACH loop, the XPath is relative. You can』t access 「higher-level」 elements inside the FOREACH loop. For example, you wouldn't be able to access the 'id' element from within the FOREACH loop.

{@url} will return the url attribute of the element you are looping through - '1-1.jpg', '1-2.jpg', etc.

{.} will return the value of the element you are looping through – in this case, each img - 'My Caption', 'Another Caption', etc.

{element_name} will return the value of the element_name child element of the element you are looping through.

 
 

Related

Inline PHP

IF Statements

Using Hooks, Filters, and Actions with WP All Import and WP All Export

Using Hooks, Filters, and Actions with WP All Import and WP All Export

WordPress makes heavy use of filters and actions to allow for its extensible nature. Collectively called hooks, those filters and actions do the heavy lifting to allow WordPress to support plugins and themes. WP All Import and WP All Export both have their own set of filters and actions that allow for modifying how each import or export works.

How Do Actions Work?

Actions are essentially a simple means for custom code you write to be called automatically when some action/event takes place. For example, say an order is made in WooCommerce and you wanted to trigger an alert at a remote API endpoint. You could call your code with the appropriate hook to make that possible.

Here's the full explanation of Actions in WordPress: https://developer.wordpress.org/plugins/hooks/actions/

How Do Filters Work?

In simplest terms, filters are actions that expect some piece of data to be returned. These filters will include a piece of data, your code would be expected to manipulate that data, then it would be returned for further processing.

Here's the WordPress reference for Filters: https://developer.wordpress.org/plugins/hooks/filters/

What Else Should I Know?

Most of the filters and actions included in WP All Import can be used directly in the Function Editor. For those that can't, it will be noted in our Action Reference and any example snippets as appropriate.

What's Next?

WP All Import Action Reference

Helpful Example Code Snippets

Related

Inline PHP

Add-On API