retrieve only sub-pages (wordpress)

Posted by Radek on Stack Overflow See other posts from Stack Overflow or by Radek
Published on 2010-05-06T12:12:09Z Indexed on 2010/05/06 12:38 UTC
Read the original article Hit count: 163

Filed under:
|

I want to list all sub-pages only one level though of one particular page. I was reading Function Reference/get pages and thought that $pages = get_pages( array( 'child_of' => $post->ID, 'parent' => $post->ID)) ; will do the trick but it is not working. It lists all pages on the same level like the page I call that code from. If I omit parent option I will get all pages even with sub-pages that I want. But I want only sub-pages.

The whole function is like

    function about_menu(){
    if (is_page('about')){

    $pages = get_pages( array( 'child_of' => $post->ID, 'parent' => $post->ID)) ;
        foreach($pages as $page)
        {       
        ?>
            <h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
        <?php
        }   
    }
    }

Screen shot from WP admin and the result mine is second one

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about php