I'm looking to exclude a category from the post navigation. Originally, I looked up manipulating <?php the_post_navigation(); ?> to exclude categories, but a few posts I read (like this) pointed me towards using <?php previous_post_link(); ?> and <?php next_post_link(); ?> instead.

Here's what I've put together so far:

<div class="left col-6">
    <h5>Previous Post</h5>
        <small><?php previous_post_link('%link', '%title', $excluded_terms); ?> </small>
<div class="right col-6 text-right">
    <h5>Next Post</h5>
    <small><?php next_post_link('%link', '%title', $excluded_terms); ?> </small>

With $excluded_terms = '463';

The problem I'm running into is that this only cycles through ONE post category and excludes posts from this ONE category that are also in category 463. I'm trying to cycle through ALL post categories except category 463. Thoughts?

Thanks in advance!

1 Answer 1


Check the signature of the function:

next_post_link( string $format = '%link &raquo;', string $link = '%title', bool $in_same_term = false, array|string $excluded_terms = '', string $taxonomy = 'category' );

Excluded terms should be the fourth argument. Your code is passing a "true-ish" argument to $in_same_term.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.