Skip to content

Instantly share code, notes, and snippets.

@kosinix
Created February 3, 2014 11:12
Show Gist options
  • Select an option

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

Select an option

Save kosinix/8782153 to your computer and use it in GitHub Desktop.
Wordpress flat list
<?php
function get_pages_flattened_tree(&$flattened_list, $parent_id=0, $level=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['level'] = $level;
$flattened_list[] = $holder;
get_pages_flattened_tree($flattened_list, $page->ID, $level+1); // Call function recursively
}
}
}
$flattened_list = array();
get_pages_flattened_tree($flattened_list);
var_dump($flattened_list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment