Created
February 3, 2014 11:12
-
-
Save kosinix/8782153 to your computer and use it in GitHub Desktop.
Wordpress flat list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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