Prev / Next Post Same taxonomy Custom Post Type

I have a custom post type “cases” and a custom taxonomy “before-after-gallery”.
On my single-case.php my prev and next post links are jumping from one category to another.

<?php next_post_link(‘%link’, ‘Next Case’, TRUE , null , ‘before-after-gallery’);?>

I am telling WP to stay in the same term and not sure why its jumping. I have spent hours trying multiple solutions but no matter what I can not get the post to stay in the same category.

This only happens on the cases in which have multiple terms on each case.
I have tried to omit the other terms but I can not find a way to say “this is my current term” and get the id of that term and omit others.

Running a standard wp loop

Read more here:: Prev / Next Post Same taxonomy Custom Post Type

Leave a Reply

Your email address will not be published. Required fields are marked *