【发布时间】:2019-10-24 12:35:11
【问题描述】:
我的 WordPress 网站在 PHP 更新之前运行良好,我没有更新在线网站的版本,但我在本地服务器上进行实验的那个网站检测到以下问题。
出现的消息是:
“警告:array_merge():参数 #19 不是 C:..php 中第 1004 行的数组”
似乎发生在array_merge函数中。
<?php
$resume = get_posts(
array(
'post_type' => array('post', 'events'),
'numberposts' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'custom_filter',
),
array(
'key' => 'location_latitude',
),
),
)
);
foreach ($resume as $post) {
$meta[] = get_post_meta($post->ID, 'custom_category', true);
}
$oneDimensionalArray = call_user_func_array('array_merge', $meta); // Problem - line 1004 //
$unique = array_unique($oneDimensionalArray);
for ($i = 0; $i < (is_array($oneDimensionalArray) ? count($oneDimensionalArray) : 0); $i++) {
if (!in_array($oneDimensionalArray[$i], $unique)) {
$unique[] = $oneDimensionalArray[$i];
}
}
sort($unique); /* Sort array by value alphabetically */
foreach ($unique as $value) {
$resume2 = get_posts(
array(
'post_type' => array('post', 'estabelecimentos', 'eventos', 'parceiros', 'noticias'),
'numberposts' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'custom_category',
'value' => $value,
'compare' => 'LIKE',
),
array(
'key' => 'location_latitude',
),
),
)
);
$count = count($resume2);
?>
<label title="<?php echo $value; ?> (<?php echo $count; ?>)"><input type="checkbox" class="chkbox"
data-value="<?php echo $value; ?>"
name="category[]"
value="<?php echo $value; ?>"><?php echo $value; ?>
<span> (<?php echo $count; ?>)</span></input></label>
<?php } ?>
【问题讨论】:
-
它看起来像
$meta不是数组,请尝试检查此变量中的内容。
标签: php wordpress array-merge