• Hello,

    I am developing a site with several post types, and I wanted to have next/prev post links which iterate across more than one custom post type. The default behaviour of next_post_link() and prev_post_link() gives you the next/prev post in that post type, but I would like to be able to specify which custom post types to iterate across.

    Is there anyone who has found a relatively simple way to do this?

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter shibbymintay

    (@shibbymintay)

    Just for anyone’s reference – I found a stackoverflow post on the topic. I needed to do a bit of tweaking but it’s a good start for those of you needing the same functionality!

    https://stackoverflow.com/questions/10376891/make-get-adjacent-post-work-across-custom-post-types

    Moderator bcworkz

    (@bcworkz)

    Sure, that looks like it’ll work, but it’s a lot of fuss just to include other post types. You can include other post types by using the dynamic filter "get_{$adjacent}_post_where". Just sayin’ ?? Thanks for coming back and presenting a workable answer!

    The filter is for the WHERE clause of the SQL query used to get the next/prev post for the normal WP post link functions. Your callback would replace the equivalent of "p.post_type = {$post->post_type}" with something like p.post_type IN ('post','my_cpt','foobar').

    The filter is applied in /wp-includes/link-template.php. The inline docs there give you the details.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Next/Prev Post links across multiple post types?’ is closed to new replies.