WordPress – Get previous/next post in deepest child category?

For the life of me I cannot find any solution to this anywhere. I have a wordpress site with a number of categories and child categories.

  • Featured Posts
  • Cat A
  • Cat B
  • > Subcat B
  • > Subcat B
  • Cat C
  • Cat D
  • > Subcat D

I would like to be able to find the previous/next posts in the deepest child category, so that the previous/next buttons stay within these categories or subcategories. A number of these posts are also in the ‘Featured Posts’ category.

Read More

Somehow I haven’t come across anything solution for this as the existing get_previous_post get_next_post functions have a boolean for limiting to posts of the same category, but then it will include posts also in the Featured Category as well as posts in the same parent category.

I’ve tried adding all parent and featured categories to the ‘excluded categories’ function but it seems to have no effect. Any help greatly greatly appreciated,
Thank you!

Related posts

Leave a Reply

1 comment