WordPress.org

Make WordPress Core

Changeset 3321


Ignore:
Timestamp:
12/16/05 09:50:10 (10 years ago)
Author:
ryan
Message:

get_children()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r3320 r3321  
    593593    } else { 
    594594        return $_post; 
     595    } 
     596} 
     597 
     598function &get_children($post = 0, $output = OBJECT) { 
     599    global $post_cache, $wpdb; 
     600 
     601    if ( empty($post) ) { 
     602        if ( isset($GLOBALS['post']) ) 
     603            $post_parent = & $GLOBALS['post']->post_parent; 
     604        else 
     605            return false; 
     606    } elseif ( is_object($post) ) { 
     607        $post_parent = $post->post_parent; 
     608    } else { 
     609        $post_parent = $post; 
     610    } 
     611 
     612    $post_parent = (int) $post_parent; 
     613 
     614    $query = "SELECT * FROM $wpdb->posts WHERE post_parent = $post_parent"; 
     615 
     616    $children = $wpdb->get_results($query); 
     617 
     618    if ( $children ) { 
     619        foreach ( $children as $key => $child ) { 
     620            $post_cache[$child->ID] =& $children[$key]; 
     621            $kids[$child->ID] =& $children[$key]; 
     622        } 
     623    } else { 
     624        return false; 
     625    } 
     626 
     627    if ( $output == OBJECT ) { 
     628        return $kids; 
     629    } elseif ( $output == ARRAY_A ) { 
     630        foreach ( $kids as $kid ) 
     631            $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]); 
     632        return $weeuns; 
     633    } elseif ( $output == ARRAY_N ) { 
     634        foreach ( $kids as $kid ) 
     635            $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID])); 
     636        return $babes; 
     637    } else { 
     638        return $kids; 
    595639    } 
    596640} 
Note: See TracChangeset for help on using the changeset viewer.