Post “pager” nav for sibling posts failing
-
I created a “pager” of sorts which is essentially a simple way to navigate between posts of the same taxonomy term. This seems to work fine except for a few examples where it’s pulling in posts from other categories. I’ve triple checked and even re-saved these posts to ensure they only belong to a single term. I’ve tried stripping away all other code but I can’t seem to figure out what’s wrong. Is it something with my work below? I’m at a loss as to what’s going on. Is there a better way to do this all together? Any ideas are much appreciated!
<div class="work-pager cycle-pager"> <?php foreach((get_the_terms($post->ID, 'work_category')) as $currentterm) {} $args = array ( 'post_type' => 'work', 'tax_query' => array( array( 'taxonomy' => 'work_category', 'field' => 'term_id', 'terms' => $currentterm, ), ), ); $work_nav_query = new WP_Query( $args ); $current_post_ID = $post->ID; if ( $work_nav_query->have_posts() ) { while ( $work_nav_query->have_posts() ) { $work_nav_query->the_post(); $class = get_the_ID($work_nav_query) == $current_post_ID ? 'cycle-pager-active' : '' ; ?> <span class="<?php echo $class . $currentterm->ID; ?>"><a href="<?php echo get_the_permalink(); ?>" title="<?php echo get_the_title(); ?>">?</a></span> <?php } } wp_reset_postdata(); ?>
- The topic ‘Post “pager” nav for sibling posts failing’ is closed to new replies.