You better look at the second answer at the post you gave link. Use content-{post-type}.php
to name all the template for each post type (If you want to know how you have to break down the template to pieces of content-{post-type}.php
, then please have look at the Twenty Sixteen theme’s template-parts
directory and analyze it’s template architecture). And call them like below at your page template-
if ( have_posts() ) :
while ( have_posts() ) : the_post();
/**
* Would include CPT content template (content-teams.php) if it exists
* or content.php otherwise.
*/
get_template_part( 'content', get_post_type( $post ) );
endwhile;
endif;
This way you can get the post type of current post by get_post_type( $post )
and assign it to the content related to the post type. And for your loop, it’ll look kinda like below-
$your_post_types = array(
'atoz_key',
'post_type_2',
'post_type_3',
'post_type_4'
);
foreach($your_post_types as $p_type ) {
$args = array(
'post_type' => $p_type,
'posts_per_page' => 10
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'template-parts/content', $p_type );
endwhile;
}