Archived topic
Next / Previous links on single content (custom post type)
4 replies · Started by Matthew on February 10, 2020
Had a good look around but couldn't find an answer to this... I bet it's something simple though!
I have a custom post type, and several custom taxonomies.
When I view a single post from this custom post type, how can I make the next / previous links only show links to posts with the same post type AND matching one of the custom taxonomies on the currently viewed post.
For example, the post type could be "Figures" with a custom taxonomy of "Year". If I am viewing a "Figure" from the "Year" 1985, the next / previous should only show figures from 1985. Currently I can only get it to show links to all figures.
Thanks,
Matt
Just stumbled upon a solution to this in the "General Setting" and "Reading" section (after installing a plugin)
There's an option there to "Keep Pagination in Same Taxonomy" and it gives you tick boxes for all Taxonomies.
Would be interested to know if there is a way to do this with a function though.
Thanks,
Matt
Hi there,
maybe the filter Tom provides here:
https://generatepress.com/forums/topic/behavior-of-next-previous-post-links/#post-884910
Hi,
That didn't work but I found out how to do it.
previous_post_link( '%link', '%title', TRUE, ' ', 'MY-CUSTOM-TAXONOMY' );
and
next_post_link( '%link', '%title', TRUE, ' ', 'MY-CUSTOM-TAXONOMY' );
give me the result that I was looking for, so I don't need that extra plugin now either.
Thanks,
Matt
Glad to hear you found a solution