Skip to content

Instantly share code, notes, and snippets.

@johnmccole
Last active December 12, 2017 17:39
Show Gist options
  • Save johnmccole/25f4619f4bee04d40e9e293f0f25fc27 to your computer and use it in GitHub Desktop.
Save johnmccole/25f4619f4bee04d40e9e293f0f25fc27 to your computer and use it in GitHub Desktop.
Copy to you themes template, update the name of the CPT as required.
<?php
global $post;
if ( isset ($post) ){
$post_parent = $post->ID;
if ( !empty($post->post_parent) ){
$post_parent = $post->post_parent;
}
$args = array( 'posts_per_page' => -1, 'post_parent' => $post->post_parent, 'post_type'=> 'custom-post-name' );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
// html content
<?php endforeach;
wp_reset_postdata();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment