0

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

1 Answer 1

0

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
}
6
  • 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. Commented Nov 18, 2011 at 19:35
  • In my example, $k is the ID. Commented Nov 18, 2011 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). Commented Nov 18, 2011 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. Commented Nov 18, 2011 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? Commented Nov 18, 2011 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.