From 8da6700ea795815db11a47ce1a90b0f03da88fbb Mon Sep 17 00:00:00 2001 From: ryan 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: http://svn.automattic.com/wordpress/trunk@2480 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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; }