Exclude posts from the_post_navigation() by category

I am using the the_post_navigation() function in WordPress like this:

<?php the_post_navigation( array(
    'prev_text' => __( 'Previous item'),
    'next_text' => __( 'Next item'),
)); ?>

This navigation goes through all my posts, but I want to exclude the posts that contain the category ‘footer’. How do I do this?

Related posts

1 comment

  1. I have used this to let the page redirects itself when the single.php goes to a post with the category ‘footer’:

     if(in_category('footer')){
        $next_post = get_next_post();
        $location = get_permalink( $next_post->ID );
        wp_redirect( $location );
        exit;
     } else {}
    

    (Works only when places above get_header();.
    Not the most beautiful solution, but it works (only for next post unfortunately)

Comments are closed.