使用Word preSS'无法使用类型stdClass的对象为阵' [英] 'Cannot use object of type stdClass as array' using Wordpress

查看:336
本文介绍了使用Word preSS'无法使用类型stdClass的对象为阵'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索蛞蝓一个字preSS门柱内侧标签,现在它可以使用来获取所有标记信息

I am trying to retrieve the slug for a tag inside a wordpress post, now its possible to get all tag info using

$tag = wp_get_post_tags($post->ID);

字preSS文档

使用这个你应该得到这样的数据恢复...

By using this you should get data returned like this...

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
       )

)

现在我要的是这应该是如下的第一项蛞蝓

Now what I want is the slug for the first item which should be as follows

$tag[0]['slug']

但这样做我收到这个PHP错误:

However by doing so I recieve this php error:

不能使用类型stdClass的对象为
  阵列

Cannot use object of type stdClass as array

谁能告诉我我在做什么错在这里?而最新最好的方式来获得蛞蝓数据

Can someone tell me what I'm doing wrong here? and whats the best way to get the slug data

推荐答案

请注意,该数组包含的对象的(实例 stdClass的),不其他阵列。因此,语法是:

Note that the array contains objects (instances of stdClass), not other arrays. So the syntax is:

$tag[0]->slug

这篇关于使用Word preSS'无法使用类型stdClass的对象为阵'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆