Ian*_*Ian 25 php arrays tags wordpress
我正在尝试在wordpress帖子中检索标签的slug,现在可以使用获取所有标签信息
$tag = wp_get_post_tags($post->ID);
Run Code Online (Sandbox Code Playgroud)
关于Wordpress Docs的更多信息
通过使用这个你应该得到这样的数据...
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
)
)
Run Code Online (Sandbox Code Playgroud)
现在我想要的是第一个项目的slug应该如下
$tag[0]['slug']
Run Code Online (Sandbox Code Playgroud)
但是通过这样做我收到这个PHP错误:
不能使用stdClass类型的对象作为数组
谁能告诉我这里我做错了什么?以及获取slug数据的最佳方法
rid*_*rid 55
请注意,该数组包含对象(实例stdClass
),而不包含其他数组.所以语法是:
$tag[0]->slug
Run Code Online (Sandbox Code Playgroud)