I have two taxonomies for categories of custom post type 'items'; 'type' and 'group'. They are not exclusive so one hierarchical taxonomy won't work although to an extent, as you'll see, they are hierarchical. So, for instance, I have a group 'group1' which may be in more than one type.
What I need to do is produce a taxonomy page 'type1' that list all the 'groups' with 'type1. It's easy enough to produce a list of posts in 'group1' but I don't know how to list the 'groups' that contain 'items' with type 'type1'.
I can see the logic but I'm struggling to produce the code. As these questions work better with some code, I'll update as I go.
This is on a page taxonomy-type.php;
// First get the type
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$type = $term->slug;
// loop through all 'type1' posts
while ( have_posts() ) : the_post();
// get all the terms for 'group'
$group_terms = get_terms( 'group' );
//print_r($group_terms);
// loop through all the terms;
foreach ($group_terms as $group_term) :
// if this post in in our taxonomy list it
if (has_term($type, 'type', $post->ID)) {
echo"<li>".$group_term->name."</li>";
}
endforeach;
endwhile;
Produces every post with all terms repeated !! My logic here is flawed, I'm looping through the posts when really what I need is to loop though the term 'group' and find if there's any posts for that term in this term 'type'