我有一些自定义帖子类型,其中两个共享自定义分类法。
有没有办法只列出一种自定义帖子类型的分类术语?
目前,我可以得到一个术语列表,并按照我的意愿显示它们,但这是两种自定义帖子类型的混合。我需要一种方法来过滤掉其他类型的帖子。
这是我的侧边栏中的内容。php:
<?php
$post_type = get_post_type();
if($post_type == \'artists\' || $post_type == \'educations\') {
$taxonomy = \'art_categories\'; // Sharing same taxonomy
} else {
$taxonomy = $post_type.\'_categories\'; // Other post type taxonomy
}
$term = get_term_by("slug", get_query_var($taxonomy), $taxonomy);
$children = get_term_children($term->term_id, $taxonomy);
if(empty($children)) { // Cats with NO kids
$parent = $term->parent;
} elseif($term->term_id > 0) { // Cats with kids
$parent = $term->term_id;
} else { // TOP Level Cats
$parent = 0;
}
$args = array(
"type" => $post_type,
"taxonomy" => $taxonomy,
"parent" => $parent,
"exclude" => 2,
);
$categories = get_categories($args);
if($categories) {
echo "<ul>";
foreach($categories as $cat) {
echo "<li class=\'cat-item\'>";
echo "<a href=\'" . get_term_link($cat) . "\'>" , $cat->name , "</a>";
echo "</li>";
}
echo "</ul>";
}
?>