根据帖子类型显示所有分类 [英] Display all taxonomy based on post type
问题描述
我只想显示基于帖子类型的分类术语,以便我可以根据它们的分类显示和过滤项目.
I just want to display a taxonomy term based on post type so that I can display and filter the items based on their taxonomy.
我下面的代码显示了每个分类法.我希望它只是一个特定的帖子类型出版物
My code below displays EVERY taxonomy. I want it to be only a specific post type Publication
<?php
$taxonomy = 'articletype';
$tax_terms = get_terms( $taxonomy, array(
'post_type' => 'publication'
) );
?>
<?php
foreach ($tax_terms as $tax_term) {
?>
<button class="button" data-filter=".<?php echo $tax_term->slug;?>" >
<?php echo $tax_term->name;?>
</button>
<?php } ?>
推荐答案
尝试使用 Codex 函数参考/获取对象分类法.
用法:
<?php get_object_taxonomies( $object, $output ); ?>
参数:
$object:(数组|字符串|对象)(必需):帖子类型的名称,或帖子对象(帖子中的行).
$object: (array|string|object) (required): Name of the post type, or a post object (row from posts).
$output:(字符串)(可选):要返回的输出类型,分类名称"或对象".
$output: (string) (optional): The type of output to return, either taxonomy 'names' or 'objects'.
返回值:
(数组):给定帖子类型/帖子对象的所有分类名称或对象.
(array): All taxonomy names or objects for the given post type/post object.
您也可以访问原始的codex 页面以获取示例和更多信息.
also you can visit the original codex page to get examples and more info.
这篇关于根据帖子类型显示所有分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!