简体   繁体   English

wordpress stdClass 对象元素访问

[英]wordpress stdClass Object elements access

I want to fetch the term_taxonomy_id from the array below but every time it gives me the following error.我想从下面的数组中获取term_taxonomy_id但每次它都会给我以下错误。

Catchable fatal error: Object of class WP_Error could not be converted to string in C.....可捕获的致命错误:类 WP_Error 的对象无法在 C 中转换为字符串.....

 Array
 (
   [0] => stdClass Object
    (
        [term_id] => 5
        [name] => fonts
        [slug] => fonts
        [term_group] => 0
        [term_taxonomy_id] => 5
        [taxonomy] => category
        [description] => 
        [parent] => 0
        [count] => 2
        [object_id] => 96
        [cat_ID] => 5
        [category_count] => 2
        [category_description] => 
        [cat_name] => fonts
        [category_nicename] => fonts
        [category_parent] => 0
    )
)

What have you tried to get that error?你试图得到什么错误? Try this:尝试这个:

foreach($yourarray as $term){
  echo $term->term_taxonomy_id;
}

最好最简单的方法

$array = json_decode(json_encode($object), true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM