From 4e79fa55fed5fca346bc119ceadf853371105f29 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 16 Dec 2005 09:50:10 +0000 Subject: [PATCH] get_children() git-svn-id: http://svn.automattic.com/wordpress/trunk@3321 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 7d61ed43d..fb87dd797 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -595,6 +595,50 @@ function &get_post(&$post, $output = OBJECT) { } } +function &get_children($post = 0, $output = OBJECT) { + global $post_cache, $wpdb; + + if ( empty($post) ) { + if ( isset($GLOBALS['post']) ) + $post_parent = & $GLOBALS['post']->post_parent; + else + return false; + } elseif ( is_object($post) ) { + $post_parent = $post->post_parent; + } else { + $post_parent = $post; + } + + $post_parent = (int) $post_parent; + + $query = "SELECT * FROM $wpdb->posts WHERE post_parent = $post_parent"; + + $children = $wpdb->get_results($query); + + if ( $children ) { + foreach ( $children as $key => $child ) { + $post_cache[$child->ID] =& $children[$key]; + $kids[$child->ID] =& $children[$key]; + } + } else { + return false; + } + + if ( $output == OBJECT ) { + return $kids; + } elseif ( $output == ARRAY_A ) { + foreach ( $kids as $kid ) + $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]); + return $weeuns; + } elseif ( $output == ARRAY_N ) { + foreach ( $kids as $kid ) + $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID])); + return $babes; + } else { + return $kids; + } +} + function set_page_path($page) { $page->fullpath = '/' . $page->post_name; $path = $page->fullpath;