From 7413ccfe727ba3dcbb0e850fb025113ae46ae2ad Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sun, 27 Mar 2005 22:17:23 +0000 Subject: [PATCH] Get all generations of page children, not just the first, when using child_of. http://mosquito.wordpress.org/view.php?id=1171 git-svn-id: https://develop.svn.wordpress.org/trunk@2480 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/template-functions-post.php | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index 62407c1b63..c7c6b75175 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -250,8 +250,27 @@ function the_meta() { // Pages // +function &get_page_children($page_id, &$pages) { + global $page_cache; + + if ( empty($pages) ) + $pages = &$page_cache; + + $page_list = array(); + foreach ($pages as $page) { + if ($page->post_parent == $page_id) { + $page_list[] = $page; + if ( $children = get_page_children($page->ID, $pages)) { + $page_list = array_merge($page_list, $children); + } + } + } + + return $page_list; +} + function &get_pages($args = '') { - global $wpdb, $page_cache; + global $wpdb; parse_str($args, $r); @@ -269,15 +288,9 @@ function &get_pages($args = '') { } } - $post_parent = ''; - if ($r['child_of']) { - $post_parent = ' AND post_parent=' . $r['child_of'] . ' '; - } - $pages = $wpdb->get_results("SELECT * " . "FROM $wpdb->posts " . "WHERE post_status = 'static' " . - "$post_parent" . "$exclusions " . "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); @@ -287,6 +300,9 @@ function &get_pages($args = '') { // Update cache. update_page_cache($pages); + if ($r['child_of']) + $pages = & get_page_children($r['child_of'], $pages); + return $pages; }