I have a few custom post types and two of them are sharing a custom taxonomy.
Is there a way to list the terms of that taxonomy for only one of the custom post types?
At the moment I can get a list of the terms and display them how I want, but its a mix of both custom post types. I need a way to somehow filter out the other post type.
Heres what I've got in my sidebar.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>";
}
?>