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.

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
add comment

2 Answers

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
add comment

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:

<?php
// 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
if(!empty($all_children)){
    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
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.