Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here's my code:

        $args = array(
            'child_of' => $CurrentPage
            );
        $children = get_pages( $args );
        foreach ($children as $child) {
            foreach ($child as $key => $value) {
            echo $key['post_title'];
            }
        };

And output:

IpppppppcppptpppppgmppcfIpppppppcppptpppppgmppcf

The output appears to be the first character of the $key, repeated over both children.

ID , post_author , post_date , post_date_gmt , post_content , post_title , etc.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You're doing one to many loops. What you want to be doing is this:

$args = array(
    'child_of' => $CurrentPage
);
$children = get_pages( $args );
foreach ($children as $key => $value) {
    echo $key['post_title'];
};

Or you could also:

$args = array(
    'child_of' => $CurrentPage
);
$children = get_pages( $args );
foreach ($children as $child) {
    echo $child->post_title;
};

It's entirely up to you, but since you already know what elements each $child has, why not stick to the same syntax as used in the get_pages() Codex article?

share|improve this answer
add comment

Your Answer

 
discard

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.