My JSON import URL has a field, which sometimes contains a single text or an array.
JSON Array:
wp_u_umlaufart
0 "Personal"
1 "Organisation"
Simple Text:
wp_u_umlaufart "Organisation"
With the function I tried to check if it is an array, if yes then return this as string and if not then just the text.
My Function:
function my_array_convert( $content ) {
if (is_array($content)) {
$converted_arr = implode(",", $content);
return $converted_arr;
} else {
return $content;
}
}
Unfortunately, only the texts arrive, an array is not returned.
I changed the function to:
function my_array_convert( $content ) {
$obj = json_decode(json_encode($content), true);
if (is_array($obj)) {
$converted_arr = implode(",", $obj);
return $converted_arr;
} else {
return $content;
}
}
WPIMPORT does not output this correctly, I have not found an error so far.
But if i put this in my php Sandbox it will work:
<?php
$content = ["Personal","Organisation"];
$obj = json_decode(json_encode($content), true);
echo is_array($obj) ? 'Yes Array' : 'No Array';
if (is_array($obj)) {
$converted_arr = implode(",", $obj);
echo $converted_arr;
} else {
echo $content;
}
?>

