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?
- Post URL redirecting to homepage
- Submit post and upload image from front-end
- Linking Two Post Types
- Pre get posts for single post
- How do I write this SQL statement for Posts written in last 24 hours?
- 960gs different classes on teasers posts
- Structuring a product catalogue in WordPress [closed]
- How can I fix a slow redirect after form submit from frontend (no plugin)?
- Post Rank on Single Post page based on custom field
- Change Post Title Edit Box
- Multiple information using custom post type
- Disable feeds for specific custom post types
- Disabling post_type in URL
- Before Delete Post
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Check Title Unique Or Not and If not error message and dont save
- I am having a problem with form updating/editing WordPress post on the frontend
- How to filter the taxonomy terms based on another taxonomy term
- Why my custom post posts aren’t showing (404 error / page not found)
- Automaticly add slug to posts
- Shortcode for display posts on home page show only one post
- How to call custom single post?
- How to Separate CPT From Regular Posts?
- Remove rows in the manage post/page view
- Remove single page for custom post type
- Display only one post each WEEK
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Set a checkmark in a category based on a URL-parameter
- Portfolio Page for Classic Posts
- Limit the post for differents custom post type in the same wp_query
- Some posts from custom post type to subdomains
- 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
- Stores category posts in an array
- 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?
- Display post from custom post type
- Custom post type title of each author in his own post
- 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
- A sports wordpress website
- WordPress giving me the index
- Custom Posttype URL
- Display custom post front end filter by ACF equals current user
- 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 do I find the count of the current post?
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- How can I write slugs / permalinks as: custom post type -> custom taxonomy and custom post type -> custom taxonomy (one CPT and many taxo)?
- 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
- Add input radio menu to post
- How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
- 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
- Custom Post By Category
- Widget area for individual posts (custom post type)?
- Change Custom Post Type to Post + Category
- 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
- Get post from Category by Priority
- Edit single page from plugin
- Show custom post type under last posts configuration
- Custom Post Type used for FAQs Accordion
- Two single.php files?
- How to Associate Posts with Pages
- delete custom post type using a submit form
- Custom Post Type children and grand-children in one list
- 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 Do I Add a Custom Post Type URL to Content?
- is therer any wordpress function to retrieve a specific html element from post content
- button onclick with get_post_permalink