• Resolved pariahcabal

    (@pariahcabal)


    Hello there,

    I would like to edit the “Next post” & “Previous post” blocks to ONLY display posts from the same category as the current post. Could someone help me with this, please?

    I’m not a coder, but have installed the WP Code “Code Snippets” plug-in.

    Thank you!

    • This topic was modified 2 years, 3 months ago by pariahcabal.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use the adjacent_post_link hooks to change the URL, and use the get_next_post_link function with $in_same_term to get the next/previous post in the same category. Something like this (I haven’t tested it):

    
    add_filter('next_post_link', function($output){
      return get_next_post_link('%link', '%title', true);
    })
    

    Same for the previous link using previous instead of next.

    Let me know if that helps.

    • This reply was modified 2 years, 3 months ago by luisherranz.
    Moderator Kathryn Presner

    (@zoonini)

    I’m marking this as resolved since it’s been a while since we’ve heard from you. If you need help with anything else, don’t hesitate to start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Make next/previous post blocks fetch from same category only’ is closed to new replies.