Based on this comment:
I would like to display all posts on the single-custom-post-type
You’re saying that, in the single CPT post view, you want to display both the single CPT post, and also a list of all CPT posts in the same category.
To do that:
- Create
single-{post-type}.php
-
The queried single CPT post is output via the default loop:
if ( have_posts() ) : while ( have_posts() ) : the_post(); // Loop markup here endwhile; endif
-
You will then need to retrieve the appropriate category:
$cpt_cats = get_the_category(); $cpt_cat = $cpt_cats[0]->term_id;
-
You will then need to add a secondary query to query all CPT posts in the given category
$cpt_query = new WP_Query( array( 'post_type' => $cpt_slug, 'cat' => $cpt_cat, 'posts_per_page' => -1 ) );
-
You will then need to create a custom loop to output your custom query:
if ( $cpt_query->have_posts() ) : while ( $cpt_query->have_posts() ) : $cpt_query->the_post(); // Secondary loop markup here endwhile; endif; // Don't forget this wp_reset_postdata();
(You will need to change the custom query parameters to suit your needs, and fill in the HTML markup where appropriate.)