I would take advantage of post-type hierarchy, and the single-{cpt}.php
template file, to accomplish everything you’re after.
You can use $post->post_parent
(recursively) to determine if the current CPT is a parent, child, or grandchild, and also to query content from parent and grand-parent CPTs for output.
CPT Hierarchy
You can create a custom function to determine the hierarchy of the current CPT; e.g.:
function wpse121567_get_cpt_hierarchy() {
// Make sure it's the right CPT
if ( 'cpt-slug' != get_post_type() ) {
return false;
}
// Globalize the post object
global $post;
// Parent CPT
if ( 0 == $post->post_parent ) {
return 'cpt-parent';
}
// Not a parent CPT, so fetch current post parent
$parent = get_post( $post->post_parent );
// Child CPT
if ( 0 == $parent->post_parent ) {
return 'cpt-child';
} else {
return 'cpt-grandchild';
}
}
Parent CPT
The “parent” CPT can simply use the normal loop to display the debate title, content, etc.:
if ( 'cpt-parent' == wpse121567_get_cpt_hierarchy() ) {
// Normal loop here
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Normal loop markup
endwhile; endif;
}
Child CPT
The “child” CPT can fetch the parent CPT’s comments using get_comments()
and display them:
if ( 'cpt-child' == wpse121567_get_cpt_hierarchy() ) {
// Globalize post object
global $post;
// Output Parent CPT title and content
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
// Fetch parent CPT comments
$parent_cpt_comments = get_comments( array(
'post_id' => $post->post_parent,
'status' => 'approve'
) );
// Loop through parent CPT comments
foreach ( $parent_cpt_comments as $comment ) {
// Output comment list markup here
}
}
Grandchild CPT
The “grandchild” CPT can fetch the Parent CPT’s statistics (using whatever method you choose):
if ( 'cpt-grandchild' == wpse121567_get_cpt_hierarchy() ) {
// Comment Stats code goes here
}
All in one template file single-{cpt}.php
Putting it all together:
get_header();
// Parent CPT
if ( 'cpt-parent' == wpse121567_get_cpt_hierarchy() ) {
// Normal loop here
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Normal loop markup
endwhile; endif;
}
// Child CPT
else if ( 'cpt-child' == wpse121567_get_cpt_hierarchy() ) {
// Globalize post object
global $post;
// Output Parent CPT title and content
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
// Fetch parent CPT comments
$parent_cpt_comments = get_comments( array(
'post_id' => $post->post_parent,
'status' => 'approve'
) );
// Loop through parent CPT comments
foreach ( $parent_cpt_comments as $comment ) {
// Output comment list markup here
}
}
// Grandchild CPT
else if ( 'cpt-grandchild' == wpse121567_get_cpt_hierarchy() ) {
// Comment Stats code goes here
}
get_footer();