Try this:
<?php
$current_id = get_the_ID();
$next_post = get_next_post();
$next_id = $next_post->ID;
$cpt = get_post_type();
$cpt_array = array($current_id, $next_id);
$args = array(
'post_type' => $cpt,
'post__in' => $cpt_array,
'order_by' => 'post_date',
'order' => 'ASC',
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while($the_query->have_posts() ): $the_query->the_post();
echo '<h2>'.the_title().'</h2>';
endwhile;
endif;
wp_reset_postdata();
?>
Tested locally and seems to work fine.
get the current post id
get the next post id
get the current post post type
run query
Related Posts:
- Display “Post 2 of 4” on single post page?
- Assign for all post of a post type a specific single-post template
- How to set class to “current-page” on the currently viewed single post within a CPT
- How to make a list of posts displaying them 5 by 5 with a “next posts” link?
- Remove slug from custom post type post URLs
- How to get post content by calling ajax?
- Get category id from post id of a custom post type
- Limit widget to a specific registered sidebar
- WP_List_Table Inside Metabox Not Working on Submit
- Edit the “Post updated. View post” link
- How to hook get_terms() to only show count of posts that have custom meta
- How Can the Users Make a “Playlist” of Posts?
- Create Post tabs in single-{content-type}.php with Custom Field values
- Disable single pages and archives and keep preview
- Missing the first 6 Posts and displaying posts that are after the latest 6
- Add extra parameters after permalink?
- How do I check if a posts status is set to draft or pending?
- Adding Custom Taxonomy to WordPress default Post type
- Post type hierarchy
- Get the post children count of a post
- Quickest way to get last or oldest post date – WP Query
- Disable single view in register_post_type [duplicate]
- Redirect Single Post CPT (Custom Post Type) to a specific URL
- Need post_type_archive_title function but in ‘single’
- WP_Query is printing out only one post when posts_per_page is set to multiple
- How to get all posts except for one post from a certain custom post type?
- Exclude child pages from archive.php
- Made Custom Post Types, but single.php not working
- How to get the post type from a category id?
- Using The REST API How To Pull All Custom Posts?
- How do I display tags for a custom post type single page?
- List children on child post
- Restrict custom post type from appearing with ?post_types=
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- How do I do this with WordPress? Taxonomies?
- Display Ad on Specific Categories
- Single template showing all posts of that type
- Show titles, date of all posts on single category page
- Several post types on WP Query by tag and taxonomy
- Set up post page like JAMA articles
- Shortcode not working with post counter
- Changing default ‘posts’ parameters with register_post_type_args
- Admin Column does not populate with data
- How to display single post from custom post type loop?
- Allow users to create posts without logging in?
- Not Able To Render Single-CustomPostType.php File
- Check post on publish for blank title
- Different Limit number of post on different archive page
- How to change “post_class()” for a custom post type?
- Help With Warning on creating new Post types?
- Including link to custom post type in ‘wp_list_pages’ function
- Get an array wich contains the post_name of every post that has the custom post_type “pelicula”
- Custom post types and ‘new WP_Query’
- Showing custom post type categories in the menu
- I can no longer post or even save a draft, getting the error “A post type mismatch has been detected.”
- Dynamic pages for linked categories and content
- Separate Content from gallery (custom post type)
- How to set the mainpage of a custom post type?
- displaying content of custom post type
- How to query Posts from a custom post type which contains a custom taxonomy?
- Does “Custom Post Type” can have page hierarhy option?
- Function to allow single post template based on custom taxonomy?
- How set template for “custom post type” individual post
- Extending post by email
- Checking for custom field in admin pages
- A sports wordpress website
- WordPress giving me the index
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- Settings -> Reading -> Posts Page ->Blog — is not working in my website
- Is it possible to get the specific content on the search page?
- How to mass get post editor URLs
- How to create additional rendering for custom post types?
- SELECT custom post type and its meta in SQL
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- How to create editable sections in wordpress?
- Instructor can view, edit, delete only theirs courses
- How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta
- subtracting the current post form then whole loop, which is generating all CPT titles
- Widget area for individual posts (custom post type)?
- When post is Published, insert into custom table a number – custom post type
- Making permalink for custom post type/custom taxonomy. Stuck with 404 in the single post
- update a posts of other custom post type
- Edit single page from plugin
- Show custom post type under last posts configuration
- Custom Post Type used for FAQs Accordion
- How to Associate Posts with Pages
- delete custom post type using a submit form
- Why are my wp urls showing page not found?
- Post content stays the same but permalink changes ?
- Can I set a CPT title field to a dropdown with preset options if user is of a given type?
- Styling first post using Advanced Custom Fields
- How do I display the index position of a post from a custom post type?
- How to call wordpress custom post type page
- Automatically add custom taxonomy when meta value gets to a set number or beyond
- How to make a non-public post on wordpress approval?
- How Do I Add a Custom Post Type URL to Content?
- is therer any wordpress function to retrieve a specific html element from post content
- Post content in bootstrap modal