Skip to content

Instantly share code, notes, and snippets.

@jkudish
Forked from crondeau/chilpages-looping.php
Last active October 14, 2016 08:11
Show Gist options
  • Save jkudish/6201973 to your computer and use it in GitHub Desktop.
Save jkudish/6201973 to your computer and use it in GitHub Desktop.
<?php
/**
* Notes and things that I changed:
* -- fixed indentation and spacing for WP standards
* -- posts_per_page = -1 is dangerous, what happens if the site has 1000000 posts, the server will explode - find a high but sane limit
*/
// loop through the sub-pages of your custom post type
$childpages = new WP_Query( array(
'post_type' => 'work',
'post_parent' => $this_page,
'posts_per_page' => 100,
'orderby' => 'menu_order'
) );
while ( $childpages->have_posts() ) : $childpages->the_post(); ?>
<section>
<h2 class="title"><a href="#"><?php the_title(); ?></a></h2>
<div class="content">
<?php the_content();?>
<?php $this_subpage = $post->ID; ?>
<?php
//Loop through the sub-pages of the child pages next
$subpages = new WP_Query( array(
'post_type' => 'work',
'post_parent' => $this_subpage,
'posts_per_page' => 100,
'orderby' => 'menu_order'
));
while ( $subpages->have_posts() ) : $subpages->the_post(); ?>
<section class="subpages">
<h3><a href="#"><?php the_title(); ?></a></h3>
<div>
<?php the_content();?>
</div>
</section>
<?php endwhile; wp_reset_query(); ?>
</div><!--.content -->
</section>
<?php endwhile; wp_reset_query(); ?>
@crondeau
Copy link

Good point about posts_per_page. Didn't think about that.
I think that gist is messing about with my indentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment