[wp-testers] is this an error in codex, 3.0 beta, or my coding error?

Matt Martz matt at sivel.net
Sun May 23 19:03:21 UTC 2010

> Change $page to something like $mypage and you will be good.  There
> are numerous global vars from the global scope that can be overwritten
> which will cause such issues.  Also stay away from $post, $p, etc...

Yet another solution is to put this code into a function so that you
are not setting variables within the global scope.

Something like:

function get_child_ids( $parent = 0 ) {
    $pages = get_pages( array( 'child_of' => $parent ) );
    $pageids = array();
    if ( ! empty( $pages) ) {
        foreach ($pages as $page)
            $pageids[] = $page->ID;
    return $pageids;

echo "<pre>";
var_dump( get_child_ids(19) );
echo "</pre>";

Also just something to point out, you should generally not try to run
anything until at least the init action, not that it would have solved
anything here, just good practice.

Matt Martz
matt at sivel.net

More information about the wp-testers mailing list