Sorry if this is super "newbie", but I'm stumped. I'm trying to create a function in WP All Import that states if the cell is empty it populates with "Not Specified". Please see below:
function power_translate_data( $data ) {
$map = array(
' ' => 'Not Specified',
);
foreach ( $map as $partial_match => $mapped_value ) {
if ( stristr( $data, $partial_match ) ) {
return $mapped_value;
}
}
return $data;
}
I appreciate any help you can give. Thank you!
Sorry if this is super "newbie", but I'm stumped. I'm trying to create a function in WP All Import that states if the cell is empty it populates with "Not Specified". Please see below:
function power_translate_data( $data ) {
$map = array(
' ' => 'Not Specified',
);
foreach ( $map as $partial_match => $mapped_value ) {
if ( stristr( $data, $partial_match ) ) {
return $mapped_value;
}
}
return $data;
}
I appreciate any help you can give. Thank you!
Share Improve this question edited Oct 10, 2019 at 5:33 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Oct 10, 2019 at 5:02 Chad HChad H 11 bronze badge 2 |1 Answer
Reset to default 0- First enable wp_debug log
Second dump the array errror_log(print_r($map))
Then look at your data array, and then start out writing the function.
- Sometimes WP All Import is a pain in the ass
stristr
with' '
will attemp to find the string value of a space in the data. You want to useif ( trim($data) == $partial_match )
and set the value to''
(no space) – majick Commented Oct 10, 2019 at 9:03