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 want to pull all the children titles of certain page and put them as a link. This is what i got so far:

$my_wp_query = new WP_Query();
                    $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));

                    // Get the page as an Object
                    $oferta =  get_page_by_title('Oferta');

                    // Filter through all pages and find Portfolio's children
                    $all_children = get_page_children( $oferta->ID, $all_wp_pages );

                    echo '<pre>' . print_r( $_children, true ) . '</pre>';

Now, how can I get page titles from $all_children ?

share|improve this question

What you put doesn't make much sense, as it turns a 1 step action, into a 4 step action

Why not just put:

$oferta =  get_page_by_title( 'Oferta' );
$my_query = new WP_Query( array(
    'post_type' => 'page',
    'post_parent' => $oferta->ID
) );
share|improve this answer

I see you were following this example. You've followed it pretty much to the letter, but it doesn't do a great job of explaining what is in these objects. Try this:

// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));

// Filter through all pages and find Portfolio's children
$all_children = get_page_children( get_the_ID(), $all_wp_pages );

// echo what we get back from WP to the browser
    echo '<ul>';
    foreach($all_children as $child){
        echo '<li><a href="'.get_permalink($child->ID).'">'.$child->post_title.'</a></li>';
    echo '</ul>';

edit: made include links as indicated in title

share|improve this answer
hello i tried to use your code on my page, but i get empty Array, what do I have to change to make it work ? – Michał Lach Jun 6 '13 at 6:15
do you have child pages of the current page? – GhostToast Jun 6 '13 at 12:05

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.