I have a
single-news page in WordPress where I am looping over all the posts and conditionally updating the previous and next buttons to exclude certain categories based on the current post's category ID.
Here is what I have:
<?php if (have_posts()): ?> <?php while (have_posts()): ?> <?php the_post(); ?> <?php if ( in_category(7)) : ?> <?php $sidebar = 'blog-news'; $catagory = array(3,5,6,4,1); ?> <?php endif; ?> <nav> <ul class="pager"> <li class="prev"> <?php echo previous_post_link( "%link", "Previous", true, $catagory ); ?> </li> <li class="next"> <?php echo next_post_link( "%link", "Next", true, $catagory ); ?> </li> </ul> </nav> <?php endwhile; ?> <?php endif; ?>
The problem I'm having is that if a post has 2 categories e.g. 6 and 7, it excludes that post from the link, whereas if the post has only one category e.g. 6 then it does not exclude it.
How do I set it so that it DOES NOT exclude any post that has category 7, regardless of if it has multiple categories.