最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - How to create an array if 'empty'?

programmeradmin0浏览0评论

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
  • stristr with ' ' will attemp to find the string value of a space in the data. You want to use if ( trim($data) == $partial_match ) and set the value to '' (no space) – majick Commented Oct 10, 2019 at 9:03
  • @majick that worked beautifully. Thank you! – Chad H Commented Oct 10, 2019 at 11:19
Add a comment  | 

1 Answer 1

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
发布评论

评论列表(0)

  1. 暂无评论