function im_add_new_term($name,$tax){
if($tax == "genre"){
return wp_insert_term($name,$tax,array("slug"=>array_search ($name, $genres)))["term_id"];
} else {
return wp_insert_term($name,$tax)["term_id"];
}
}致命错误:不能在第11行的/home/pcodecom/demo.p30code.com/multimedia-2/wp-content/plugins/imdb/imdb.php中使用WP_Error类型的对象作为数组
发布于 2020-04-04 08:02:52
$genres是什么?我看不出它在任何地方都有定义。
而wp_insert_term()可能返回错误,所以请确保检查它是否是一个错误。因此,与其简单地执行return wp_insert_term($name,$tax)["term_id"],您还可以这样做:
$data = wp_insert_term( $name, $tax );
if ( ! is_wp_error( $data ) ) {
return $data['term_id'];
}https://wordpress.stackexchange.com/questions/363190
复制相似问题