Pull In Two Posts To Custom Post Type `cpt-single.php` File
I have a custom post type and in the CPT’s
cpt-single.php file I would like to pull in two posts instead of one.
The two posts will be the post the user clicked on in the relevant archive, and the next post in date order (i.e. the default post sorting method of WordPress) or the next post in that category (doesn’t matter which method). The reason for this is the posts are essentially small, useful pieces of information and having two posts pulled in will create a better SEO and user experience.
Normally when I want to pull in a set number of posts on an archive page I would use
WP_Query() and set ‘posts_per_page’ => 2` but his won’t work in this instance because such code pulls in posts that are the most recent, not the post that was clicked on the archive page (and the next most recent post after this).
Any help would be amazing.