Using get_adjacent_post
, previous_post_link
, and next_post_link
only seems to recognize items which are of the same post type. Since I have 2 custom post types is there a way to link between all previous and next post types?
Leave a Reply
You must be logged in to post a comment.
It appears this question has been asked all over the interweb with no definite answer. So I created my own function from the original
get_adjacent_post
and customized it for anyone else who needs it.The Function
Drop this in your functions.php
Usage
Basic use
For creating prev/next links
You can still modify the code if you still want to include the variables
$in_same_cat
and$excluded_categories
but if you do then I suggest you useget_adjacent_post
instead since that’s what it’s for.The previous answer it’s not longer working. Check this one out
I came up with a new one, quite more simple:
Now wherever you need the next-prev post ID just use the function like this:
Comments:
get_the_ID()
for your current post ID if you feel like it.register_post_type()
function. It falls back to ‘post’.Examples:
If you want the next or prev post permalink you can use it like this:
So with the tag it would look something like this:
Could not test it a lot so if it’s not working in some cases let me know and I’ll try to fix it / improve it.