Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Christopher Paccione
Christopher Paccione
14,831 Points

Infinite next/prev links for Custom Post Type

Hello,

I have four custom post types, and I would like to create a next/prev link that will cycle through the post types. Normally when you get to the last post type, it will just say "back" or "prev" and in my case I want it to just say "next or prev" the whole time. I will eventually replace the next and prev with arrows.

The following code works, but it is cycling through all the post types. I Just want it to cycle through a specific post type. The page from the staging site is here. http://thermflo.msistaging.com/service_tech/chris-doe/

Thank you!

                ```php
                <?php 
                if( get_adjacent_post(false, '', true) ) { 
                    previous_post_link('%link', '&larr; Previous Post');
                } else { 
                    $first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
                        echo '<a href="' . get_permalink() . '">&larr; Previous Post</a>';
                    wp_reset_query();
                }; 

                if( get_adjacent_post(false, '', false) ) { 
                    next_post_link('%link', 'Next Post &rarr;');
                } else { 
                    $last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post();
                        echo '<a href="' . get_permalink() . '">Next Post &rarr;</a>';
                    wp_reset_query();
                }; ?>
                ```