0
votes

I'm using wordpress 3.1

I got 3 types of custom types : videos, galleries and podcasts. They use the default taxonomy categories.

When viewing a single custom post let's say a video, the next_post_link() (or previous_post_link) function works as planed but it links only to the next or previous post from this custom post type.

How could I get it to display the next post from any post type? tried to search hours on google without finding anything relevant to this. Anyone facing the same issue?

1

1 Answers

2
votes

You'll need to remove the post_type clause from the SQL query used to retrieve the adjacent post. This can be done by hooking into the get_next_post_where and get_previous_post_where filters, although it's not ideal as the SQL query is passed as a single string.

add_filter('get_next_post_where', 'my_get_adjacent_post_where_filter');
add_filter('get_previous_post_where', 'my_get_adjacent_post_where_filter');
function my_get_adjacent_post_where_filter($sql) {
  return preg_replace("/ AND p.post_type = '[^']*'/", '', $sql);
}