Skip to content

Instantly share code, notes, and snippets.

@kosinix
Created February 3, 2014 05:58
Show Gist options
  • Select an option

  • Save kosinix/8779454 to your computer and use it in GitHub Desktop.

Select an option

Save kosinix/8779454 to your computer and use it in GitHub Desktop.
<?php
function get_pages_tree($parent_id=0){
$args = array(
'parent'=>$parent_id
);
$pages = get_pages( $args );
if($pages){
$list=array();
foreach($pages as $page){
$holder = (array) $page; // Cast as array
$holder['children'] = get_pages_tree($page->ID); // Call function recursively
$list[] = $holder;
}
return $list;
}
return array();
}
get_pages_tree();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment