I had a very hard time importing multiple values that were listed in a single column in CSV file into an Advanced Custom Fields (ACF) checkbox field using WP All Import. If the column had a single value, like “Spanish” then that worked great. But if the column had more than one value, like “Spanish,English” then nothing was getting imported at all.
The main mistake I made was using the “Custom Fields” section instead of the “Advanced Custom Fields Add-On” section. In the “Advanced Custom Fields Add-On” section, you need to choose the correct field group to find your field (in this example, “Languages”). When you find your field in the section that opens up, then click “Set with XPath” and drag your CSV field from the list on the right into the “Set with XPath” text field.
That’s all you have to do if the values in your CSV file exactly match the values used in your ACF checkbox field. If the values in the CSV don’t match what is in ACF, then you need to use mapping, which means you need a PHP mapping function to the “Function Editor”. The function should map your list of values in the CSV to a mapped list of values that match ACF. Here is a PHP function to do that multi-value mapping (this is adapted from a single-value mapping function provided by WP All Import)
<?php
function mapped_array($data, $map) {
if (empty($data)) {
return "";
}
// build comma separated list
$finalList = "";
$valueArray = explode(",",$data);
foreach ($valueArray as $x) {
if (!empty($finalList)) {
$finalList = $finalList . ",";
}
$finalList = $finalList . (isset( $map[$x] ) ? $map[$x] : $x);
}
return $finalList;
}
function map_languages( $data ) {
$map = array(
'Spanish' => 'spanish',
'Chinese' => 'chinese',
'American Sign Language' => 'asl',
);
return mapped_array($data, $map);
}
?}
Then you call the function in your “Set with XPath” text field, like this:
[map_languages({language[1]})]