【发布时间】:2011-02-28 15:56:06
【问题描述】:
我有点困惑。
我有一个数组:
<?php
$terms = get_the_terms($post->ID, 'pf');
print_r($terms);
?>
它输出:
数组 ( [15] => 标准类对象 ( [term_id] => 15 [name] => 文本 [slug] => 文本 [term_group] => 0 [term_taxonomy_id] => 33 [taxonomy] => pf [描述] => 一篇 PF 文章。 [父] => 0 [计数] => 3 [object_id] => 694))
我只想输出 slug(在本例中为“文本”)而不是整个数组。
所以我在做:
<?php $terms = get_the_terms($post->ID, 'pf');
echo $terms["slug"]; ?>
它什么也不输出。
这也没有给出任何结果:
echo "{$terms['slug']}";
有什么想法吗?
更新!!!
我不能使用 $term[15]->slug,因为我的脚本将基于 [taxonomy](在本例中为 pf)! :) 那么如果没有 foreach 循环就不可能做到这一点?
【问题讨论】: