Skip to content

Instantly share code, notes, and snippets.

@x1024
Created November 9, 2014 21:26
Show Gist options
  • Save x1024/3a7fcc13300116c35583 to your computer and use it in GitHub Desktop.
Save x1024/3a7fcc13300116c35583 to your computer and use it in GitHub Desktop.
WP Grandchildren
the_post();
$children = new WP_Query( array('post_type' => 'page', 'post_parent' => get_the_ID() );
$ids = array();
if ($children->have_posts()) {
while ($children->have_posts()) {
$children->the_post();
array_push($ids, get_the_id());
}
}
foreach ($ids as $id) {
$grandchildren = new WP_Query( array('post_type' => 'page', 'post_parent' => $id );
while ($grandchildren->have_posts()) {
$grandchildren->the_post();
the_title();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment