gpt4 book ai didi

PHP & WordPress : print array content

转载 作者:行者123 更新时间:2023-12-02 15:39:01 25 4
gpt4 key购买 nike

我现在很笨……

print_r($terms);

这是……

Array
(
[7] => stdClass Object
(
[term_id] => 7
[name] => Testwhatever
[slug] => testwhatever
[term_group] => 0
[term_taxonomy_id] => 7
[taxonomy] => event_type
[description] =>
[parent] => 0
[count] => 2
[object_id] => 8
)

)

如何打印 slug?我认为 print print($terms->slug) 应该可以完成这项工作,但它说:“尝试获取非对象的属性”

更新:

function get_event_term($post) {
$terms = get_the_terms( (int) $post->ID, 'event_type' );
if ( !empty( $terms ) ) {
print_r($terms);
return $terms[7]->slug;
}
}

最佳答案

它是一个对象数组(即使它只包含索引“7”处的单个条目),而不是单个对象

echo $terms[7]->slug;

有多个“事物”

foreach ($terms as $term) echo $term->slug;

关于PHP & WordPress : print array content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com