Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ';无法将stdClass类型的对象用作数组';使用Wordpress_Php_Arrays_Wordpress_Tags - Fatal编程技术网

Php ';无法将stdClass类型的对象用作数组';使用Wordpress

Php ';无法将stdClass类型的对象用作数组';使用Wordpress,php,arrays,wordpress,tags,Php,Arrays,Wordpress,Tags,我试图检索wordpress帖子中标签的slug,现在可以使用 $tag = wp_get_post_tags($post->ID); 更多信息请访问 通过使用它,您应该得到如下返回的数据 Array ( [0] => stdClass Object ( [term_id] => 4 [name] => tag2 [slug] => tag2 [term_g

我试图检索wordpress帖子中标签的slug,现在可以使用

$tag = wp_get_post_tags($post->ID);
更多信息请访问

通过使用它,您应该得到如下返回的数据

Array
(
   [0] => stdClass Object
       (
           [term_id] => 4
           [name] => tag2
           [slug] => tag2
           [term_group] => 0
           [term_taxonomy_id] => 4
           [taxonomy] => post_tag
           [description] => 
           [parent] => 0
           [count] => 7
       )

   [1] => stdClass Object
       (
           [term_id] => 7
           [name] => tag5
           [slug] => tag5
           [term_group] => 0
           [term_taxonomy_id] => 7
           [taxonomy] => post_tag
           [description] => 
           [parent] => 0
           [count] => 6
       )

)
现在我想要的是第一项的slug,应该如下所示

$tag[0]['slug']
但是,通过这样做,我收到了以下php错误:

无法将stdClass类型的对象用作 排列


有人能告诉我我做错了什么吗?获取slug数据的最佳方法是什么请注意,数组包含对象(stdClass的实例),而不是其他数组。所以语法是:

$tag[0]->slug

另一个选项应该是显式地将$tag[0]强制转换到数组中:

$t = (array)$tag[0];
$t["slug"] = ...

但无法使其工作

啊,这正是我想要的。我想我需要回到php basicsHi,而不是'slug',我将'@classId'作为要获取的名称。在标记“@”处出现语法错误,您知道解决方法吗?谢谢你。我正在调用一个不带out参数的mysql进程,然后在下一个查询中进行选择。@mtk,使用
$tag[0]->{“@classId”}
@radu,但它不起作用。我问了同样的问题。请看。我在wordpress中为我的菜单创建了一个自定义walker。不知何故,它在一个参数中同时使用了对象和数组。这个小小的代码和平解决了问题,我不知道。