Support » Developing with WordPress » next_post_link doesn’t work for only the closest category

  • Hi there,

    I am using “previous_post_link” and “next_post_link” & option “TRUE” set to output Prev and Next post title work within the same category. However, I have encountered one little problem under the following circumstance.

    1. Parent category “Noodle” and 3 child categories underneath “Pasta”, “Udon” and “Ramen”

    2. Those 3 categories have many post and at the end of each single page, I have set previous and next post_link.

    3. I want to see prev and next title link from the same category. For example. if the post is from “Pasta” category, prev and next post should only output within the “Pasta category” not from “Udon” or “Ramen”.

    4. previous and next post_link work fine in the way I want if I doesn’t select parent category “Noodle” but only “Pasta” before publishing.

    The problem is that because all the posts over 1000 have parent category “Noodle” selected, previous and next post_link output prev and next titles from all the Noodle category which has mixture of 3 different child categories “Udon, Pasta and Ramen”…

    In other words, I want to output prev and next title links from the closest category (not parents).

    It would be great if you could give me advise to avoid this situation without unselecting parent category “Noodle” one post by another.

    I hope my explanation makes sense.

    Thank you.

    • This topic was modified 10 months, 1 week ago by  palmtree.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    You said “…next_post_link() & option TRUE“. Do you mean the in_same_term parameter (the 3rd one) is TRUE? It must be, it’s the only interpretation that makes sense.

    You can prevent certain terms from being used when determining next and previous links with the excluded_terms parameter (the 4th one). Pass an array or comma separated list of term IDs you do not want the function to consider in getting the next or previous link. Such as the term ID for “Noodle” and any other top level category that you want excluded.

Viewing 1 replies (of 1 total)
  • The topic ‘next_post_link doesn’t work for only the closest category’ is closed to new replies.