How to Map Custom Fields
Mapping is used when the value you need to import to your site differs from the value in your file. A visual interface is available for mapping Custom Fields and custom taxonomies. To map elsewhere, you can use a custom PHP function.
For example, you may have a file with product categories that are written in Dutch, but you want to import these products to categories that already exist on your site with English names.
Or, your theme or plugin requires the value of a Custom Field it uses to be either 1 or 0, but in your XML or CSV file, the values are expressed as Yes or No.
You need to map the values in your file to the values you want imported to your site.
Example – Mapping For A Dropdown
In the previous article, Importing to Theme & Plugin Fields, we explained how to detect the fields used by your theme or plugins, and their possible values.
Our theme has a dropdown to specify whether a Property Listing is for rent or for sale.
The field name is rob_value, and the possible values, as stored in the database, are Rent and Buy.
Note: You can see the values as they are stored in the database by clicking inside the Value textbox for the rob_value field in WP All Import. The values stored in the database may not be the same as the values shown inside the select box in the theme. We must map the values as they are stored in the database.
Our XML file has a <rentorbuy> element that is set to FORSALE if the property is for sale (Buy), and FORRENT if the property is for rent (Rent).
Without mapping, simply dragging & dropping <rentorbuy> to the Value box for rob_value would not work because the value of <rentorbuy> is not correct for our theme.
To solve this problem, we use the Mapping feature.
Click Field Options… and then click Mapping.
A dialog box will pop up, allowing you to specify the mapping rules.
Now, when the import is run, FORSALE in your file will be translated to Buy, and FORRENT in your file will be translated to Rent, so your data will be imported correctly, as per the requirements of your theme and plugins.
Mapping Function Example
If you need to map using a PHP function elsewhere, we have an example available to share:
// Mapping function
function my_map_field( $data ) {
$map = array(
'Translate This' => 'To This New Value',
'And this' => 'To this',
'Add as many' => 'Rules',
'As you need' => 'In this array',
);
return isset( $map[$data] ) ? $map[$data] : $data;
}
Learn more about using PHP functions here: Calling PHP Functions In Your Import Configuration.
Import Any CSV, XML, or Excel to WordPress
- Any theme or plugin
- Images & galleries
- Custom fields
- Categories & tags
- Woo, ACF, Meta Box, JetEngine
Related Docs
Learn how to use custom fields when importing via WP All Import.
Learn more about serialization and importing serialized fields.
Provides instructions on how to run PHP code during the import.