我正在使用list_author_used_terms
函数获取特定作者使用的术语(自定义分类法“wossom”中的术语,用于自定义帖子类型“aya-bi-aya”)。
function list_author_used_terms($author_id){
$posts = get_posts( array(\'post_type\' => \'aya-bi-aya\', \'posts_per_page\' => -1, \'author\' => $author_id) );
$author_terms = array();
foreach ($posts as $p) {
$terms = wp_get_object_terms( $p->ID, \'wossom\');
foreach ($terms as $t) {
$author_terms[] = (string)$t->name;
}
}
return array_unique($author_terms);
}
在中author.php
模板文件,我想显示给定作者使用的术语。我喜欢这样:<?php
$user = get_user_by(\'login\',get_query_var(\'author_name\'));
$used_terms=list_author_used_terms($user->ID);
foreach ($used_terms as $ut) {
?>
<a href="<?php echo get_term_link( $ut,"wossom"); ?>"><?php echo $ut; ?></a>
<?php
}
?>
当我print_r
这个$used_terms
, 我得到了正确的数组,但是foreach
循环未显示任何内容。我尝试单独打印时出现以下错误get_term_link( $ut[0],"wossom");
:
Catchable fatal error: Object of class WP_Error could not be converted to string in C:\\xampp\\htdocs\\blog\\wp-content\\themes\\twentyten\\author.php on line
我知道这是一个纯粹的php问题,但我真的很累,试图解决它。非常感谢您的帮助。