From 494df9b02dbc16e0baf89ca8a124e06de945348b Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 16 Dec 2005 09:50:10 +0000 Subject: [PATCH] get_children() git-svn-id: https://develop.svn.wordpress.org/trunk@3321 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 7d61ed43d1..fb87dd7977 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;