当我对$parents to $parents[]
public static function get_parents($post_id = false){
if (!$post_id){
$post_id = get_the_ID();
}
if (!$post_id){
global $wpdb;
if ($wpdb->last_result && count($wpdb->last_result) == 1){
$post_id = $wpdb->last_result[0]->ID;
}
}
$parents[]= get_metadata(\'post\', $post_id, WPKWP::$META_CHILD, false);
$something=count($parents);
if (count($parents) > 0){
return $parents;
}
return false;
}
查询监视器插件显示Undefined offset: 0-wp-includes/meta.php:488 -Melding下面的代码似乎就是问题所在。如果我设置最后一行return $meta;
到return null;
错误似乎消失了。
public static function get_post_metadata($meta_value, $post_id, $meta_key, $single){
if (is_admin()){
return null;
}
remove_filter(\'get_post_metadata\', array(WPKWP::CLASS_NAME, \'get_post_metadata\'), 0);
$child_meta = get_metadata(\'post\', $post_id, $meta_key, false);
if (WPKWP::get_parent()){
$parent_meta = get_metadata(\'post\', WPKWP::get_parent(), $meta_key, false);
if (is_array($parent_meta) && is_array($child_meta)) {
$meta = array_merge($parent_meta, $child_meta);
} else {
$meta = $parent_meta;
}
} else {
$meta = $child_meta;
}
add_filter(\'get_post_metadata\', array(WPKWP::CLASS_NAME, \'get_post_metadata\'), 0, 4);
return $meta;
}