It sounds like you just need a WP_Query above your normal post loop. You can copy the single.php
template and rename it single-cpt_slug.php
. This will ensure that this loop only shows up on single posts of the post type. If you really don’t want to use a single cpt template, you could use a conditional before the loop like if( is_singular( 'cpt_slug' ) )
.
To get the most out of this I suggest checking out The Codex on WP_Query and Template Hierarchy. Toward the top of your single-cpt_slug.php
template you want to define the following:
global $post;
$secondary = new WP_Query( array(
'post_type' => 'cpt_slug',
'posts_per_page'=> 10,
'orderby' => 'rand',
'author' => $post->post_author,
) );
This defines a second query which you can loop through and display anywhere almost exactly like a normal loop:
<?php if( $secondary->have_posts() ) : ?>
<?php while( $secondary->have_posts() ) : $secondary->the_post(); ?>
<h1><a href="https://wordpress.stackexchange.com/questions/203713/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php
wp_reset_postdata(); // Normalizes Global $post Object
endif;
?>
At this point you can then continue with the normal post loop which would display the single posts content.
:: Note :: You’ll need to replace all the instance in the above code of cpt_slug
with whatever you post type slug is.