Pull Two Posts Into Custom Post Type `single-cpt.php`

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

Leave a Comment