I’ve created a custom post type like :

    register_post_type( 'foobar' ,
    array(
        'labels' => array(
            'name' => __('Foobar'),
            'singular_name' => __('Foobar')
        ),
        'public' => true,
        'has_archive' => true,
        'menu_icon' => 'dashicons-welcome-write-blog',
        'supports' => ['title', 'editor', 'thumbnail']
    )
);

After that, I’ve created multiple page templates :

single-foo.php

single-bar.php

with

/*
* Template Name: whatever
* Template Post Type: post, page, product, foobar
*/

I’d usually output the custom post type with something like:

<?php $args = array( 'post_type' => 'foobar', 'posts_per_page' => 1, 'orderby' => 'meta_value' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post();
                the_title("<h1>","</h1>");
                echo '<p>';
                the_content();
                echo '</p>';
            endwhile; ?>

I’m creating two new posts in my custom post type foobar and as a template for one post foo and the other post bar.

How can I output multiple page templates, created in one CPT on the same page?
Like, let’s say, I’ve got 7 posts in the CPT, which all have different templates and they have to be outputted on the same page.

Could it actually work like that?

Read more here: Display custom post types with multiple page templates


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: