admin管理员组文章数量:1305769
I am trying to display all of the terms for a custom taxonomy(characters
), the taxonomy is related to a custom post type(books
).
What I would like to do is display all of the terms for characters
, so say for instance I have two books
, and I add three characters
to each book
, I would like all six characters to display.
I would only like to get the names, not links, or in list form, if I could get a set of objects or an array that would be preferable.
Thank you.
I am trying to display all of the terms for a custom taxonomy(characters
), the taxonomy is related to a custom post type(books
).
What I would like to do is display all of the terms for characters
, so say for instance I have two books
, and I add three characters
to each book
, I would like all six characters to display.
I would only like to get the names, not links, or in list form, if I could get a set of objects or an array that would be preferable.
Thank you.
Share Improve this question asked Jul 10, 2011 at 18:49 Odyss3usOdyss3us 9051 gold badge12 silver badges18 bronze badges 1- Please check the link bellow: wordpress.stackexchange/a/8291/68186 – Porosh Ahammed Commented May 13, 2017 at 19:15
2 Answers
Reset to default 1I believe what you are looking for is the get_terms function. I found it looking at the code for wp_tag_cloud, here is the source of the function. This little snippet should get you what you are wanting.
$terms = get_terms("characters");
if ( empty( $tags ) || is_wp_error( $tags ) )
return;
foreach ( $terms as $term ) {
echo $term->name;
}
You can add a function to your functions.php and pass 'characters' as an argument (or the slug for your custom taxonomy) to show a comma separated list of all your terms.
function show_all_terms($taxonomy){
$taxonomy_terms = get_terms($taxonomy);
foreach($taxonomy_terms as $term){
$terms[] = $term->name;
}
if(!empty($terms)) {
echo join(", ", $terms);
}
else{
echo "No ".$taxonomy."associated with this ".get_post_type();
}
}
Now you can call this function in your templates like this:
show_all_terms('character');
// you can replace 'character' with the slug of any custom taxonomy as well.
本文标签: List custom taxonomy terms
版权声明:本文标题:List custom taxonomy terms 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741809330a2398698.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论