Skip to content

Instantly share code, notes, and snippets.

@christiaansnoei
Last active December 2, 2019 10:07
Show Gist options
  • Save christiaansnoei/d79b55b7992e424d74dd8242b57f67a2 to your computer and use it in GitHub Desktop.
Save christiaansnoei/d79b55b7992e424d74dd8242b57f67a2 to your computer and use it in GitHub Desktop.
List all child pages of a parent page in WordPress.
<?php
global $post;
$ancestors = $post -> ancestors ?? '';
if( isset($ancestors) ):
$ancestors = array_reverse($ancestors);
if( isset($ancestors[0]) ):
$current_toplevel_menu_id = $ancestors[0];
else:
$current_toplevel_menu_id = $post -> ID;
endif;
$args = array(
'child_of' => $current_toplevel_menu_id,
'post_type' => $post -> post_type,
'title_li' => '',
);
wp_list_pages($args);
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment