I have a sub-navigation for custom post type 'Projects' taxonomy called "Type":
<?php $args = array( 'post_type' => 'projects');
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $terms = get_terms('type');
$currentterm = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo '<ul class="sub-nav-menu">';
foreach ($terms as $term) {
$class = $currentterm->slug == $term->slug ? 'live' : '' ;
echo '<li><a href="'.get_term_link($term).'" class="'. $class .'">'.$term->name.'</a></li>';
}
echo '</ul>'; ?>
<?php endwhile; ?>
<?php endif; ?>
When clicking on taxonomy it takes you to the taxonomy page taxonomy-type.php.
Although this page is still showing all the custom post types not just the ones for the current taxonomy page.
<?php $args = array( 'post_type' => 'projects');
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $terms = get_terms('type'); ?>
<a href="<?php the_permalink() ?>">
<h3><?php the_title(); ?></h3>
</a>
<?php wp_reset_postdata(); ?>
<?php endwhile; ?>
<?php endif; ?>
How should I modify the loop to filter only the current taxonomy posts of the 'Type' taxonomy?