我试图获取自定义帖子类型中的所有标签" resource"。问题是我在循环之外并努力找到一种方法来使用自定义帖子类型的功能。我的类别设置也是" resource_category"
我目前的代码是:
$tax = 'post_tag';
$terms = get_terms( $tax );
$count = count( $terms );
if ( $count > 0 ): ?>
<div class="post-tags">
<?php
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, $tax );
echo '<a href="' . $term_link . '" class="tax-filter" title="' . $term->slug . '">' . $term->name . '</a> ';
} ?>
</div>
<?php endif;
有人可以帮忙吗?
答案 0 :(得分:2)
您要的是正确的标签,因为2015年的答案是列出类别而不是标签
$args = array(
'type' => get_post_type(),
'orderby' => 'name',
'order' => 'ASC'
);
$tags = get_tags($args);
foreach($tags as $tag) {
var_dump($tag->name);
}
答案 1 :(得分:0)
$args = array(
'type' => 'resource',
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
}
答案 2 :(得分:0)