use get_adjacent_post(). if nothing is returned for next/prev, get the first/last.
Edit- just noticed your custom post type, you’ll also have to filter get_previous_post_where
and get_next_post_where
to pick up your cpt.
Related Posts:
- query_posts pagination will always show identical content
- posts_per_page no limit
- Alternative to query_posts for main loop? [duplicate]
- Query posts by custom taxonomy ID
- Thumbnail (featured image) of next and previous post is not being properly displayed!
- Query posts: how to exclude results if post is in multiple categories
- query_posts ->using meta_compare / where meta value is smaller or greater or equals
- How to order posts by descending comment count on taxonomy page?
- How to use next_post_link and previous_post_link on single posts in search results
- Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?
- WP 5.8 “Query Loop” block: where to place custom query?
- Pagination on archive.php page
- adding custom fields to next and previous post link
- Best way to load page content in Fancybox popup?
- order post my meta value m/d/y format with year as included value
- _wp_page_template to dynamically use template
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Using previous_post_link and next_post_link to wrap around post sequence
- Schedule Sticky Posts
- Disable “previous link” in first post and “next link” in last post
- previous / next post with thumbnail
- Problem with single-page for my custom post
- Post in Multiple Categories to stay in current category (permalink, next previous post link)
- How to modify the query to exclude posts by slug?
- Working with Next and Prev links in Single Taxonomy Templates
- How to make my pagination loop continuously?
- How to make the list of post and load on same page with sub-pages [closed]
- How to get 4 Posts after the 5 most recent ones
- Get attachment next and previous by author only
- post_status => publish not working
- previous_post_link() next_post_link() arrow position
- How do I make archives.php for one category only?
- making random query button using $_GET
- Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
- How do I change the default sort order of a custom column on the posts page?
- Next and/or previous post content
- how to exclude “featured” posts from the main loop?
- WordPress pagination showing same posts on each page
- Order posts by condition
- Search breaks when querying main loop for category
- Authors List page – How to include only those with wp_user_level as Author
- Using ‘previous_post_link()’ & ‘next_post_link()’ on single attachment pages
- next_post_link and previous_post_link order not working properly
- Query posts by meta_key whose value is an array
- Show Blogroll of another WordPress site
- Why this code causes infinite loop?
- Each post is showing twice in my custom query…?
- query_posts() – problem with “s” parameter
- How to exclude or filter password protected posts when using next_post_link() previous_post_link
- Add Previous/Next Buttons to CPT Single Pages Only
- Page title in post query
- Question about querying posts
- How to list most popular post
- Breadcrumbs stop working on a specific template file
- How can I query for all children posts regardless of parent
- INSERT in table row fatal error
- WordPress query reverse order
- Get next post in same category not working WP 4.7.4
- How to reverse post navigation at bottom of post
- WP-API: get posts in multiple categories
- Order for custom field after the loop
- Different layout based on post amount?
- Calling Posts from Specified Cat
- Keeping get_posts’ offset and is_paged() synchronized
- pagination links not displaying
- odd behaviours from template tags
- How to get any type posts include attachments by ids?
- Modify main loop query for paged and meta key
- wordpress query_posts featured page always on top
- Create a Loop with Posts Ordered by Most Recent Comments
- Need to add a space after meta value in query_posts in wordpress for zipcode search
- next/previous post links for specific category when post belongs to multiple categories
- Tax query get first product with attribute value in pre_get_posts
- Specifying image size used in template the_content
- allow user to edit posts made by others users based on the user role
- get_previous_post_link and get_next_post_link of custom post type that share custom field value
- Ordering Posts By Meta Data
- WordPress not showing pagination links
- No duplicate tags by category
- Order posts by ACF checkbox
- previous_posts_link returns null when querying custom post type
- Post per page not working
- Show previous month’s posts
- query_posts result differs from wp_query request result
- If meta_key has value = 6 | Change the wp_posts.post_date to current date
- Multiple next / previous
- single post navigation order (NOT chronological)
- How to add a class and title attribute to the link generated by next/previous post
- Adding Category Argument into an Array for WordPress Query
- Collect posts from last 48 hours
- The_content display a different content from a previous loop
- How to go to tag archives using a form
- Run second query on page based on author of the first query
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Why doesn’t this page query work?
- Resetting a Query using wp_reset_query() or wp_reset_postdata() does not work
- Sort posts with multiple meta_keys
- Create “archives by year and week” by category template
- Next/previous post link to posts only within one or more specific categories
- How to add thumbnail support to WordPress next / previous post loop?