[英]Error: Trying to get property of non-object
I'm getting an error: 我收到一个错误:
Trying to get property of non-object on line 30
试图获取第30行上非对象的属性
On the commented line below... 在下面的评论行上...
function admin_trim_category_description( $terms, $taxonomies ){
if( 'category' != $taxonomies[0] ) return $terms;
$my_categories = array('item1','item2','item3');
foreach( $terms as $key => $term)
if(in_array(
$terms[$key]->name, //ERROR LINE HERE
$my_categories))
{
unset($terms[$key]);
}
}
What am I doing wrong? 我究竟做错了什么?
$terms[$key]
seems not to be an object. $terms[$key]
似乎不是对象。 I'd suggest you to check whatever it is an object or not with: 我建议您使用以下命令检查它是否是对象:
if (is_object($terms[$key])) { /* OK */ }
and/or check whatever the object is an instance of a specific class with: 和/或检查对象是否是特定类的实例,方法是:
if ($terms[$key] instanceof MyClass) { /* OK */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.