WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to access the page ID of the child so that I can recursively call the get_children function on that child (to get grandchildren).

    if ($CurrentPage) {
        $args = array(
            'child_of' => $CurrentPage
        $children = get_pages( $args );

        foreach ($children as $key => $value) {
                echo $key.'=>'.$value.'<br />';
        } // End foreach.
    } // End IF. 

I actually get an error: Catchable fatal error: Object of class stdClass could not be converted to string

share|improve this question
up vote 0 down vote accepted

The return set of $children is an associative array. So you can get the IDs with:

$children = get_children( $args );

foreach ($children as $k => $v) {
    echo $k;
    // do stuff with $v
share|improve this answer
If I run foreach $children as $child => $element, and I want to call the ID, I run $child['ID'] = $ID, echo $ID. I'm lost. – AlxVallejo Nov 18 '11 at 19:35
In my example, $k is the ID. – GavinR Nov 18 '11 at 20:11
Hm, if each $child holds an array of attributes: say ID = page ID, parent = parent ID, I don't believe your syntax makes sense. I'm not asking for the element ID. I'm asking for the specified page ID in the array of get_children (actually, I just switched to get_pages). – AlxVallejo Nov 18 '11 at 20:30
$children is an associative array with the page ID as the key, and the page properties the value. Do a print_r($children) for more information. Trust me - $k is the Wordpress Page ID. – GavinR Nov 18 '11 at 20:41
My output is like this: [ID] => 124 [post_author] => 1, etc... So if i want to output 124, I need to output $v where $k = ['ID']. Right? – AlxVallejo Nov 18 '11 at 20:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.