• Hi guys
    im using this code to display child pages of current page
    with their content…

    <?php
    	$mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=asc');
    	$count = 0;
    	$numberofsub = count(get_pages('depth=1&child_of='.$post->ID));
    	foreach($mypages as $page)
    	{
    		$content = $page->post_content;
    		if($count == $numberofsub)
    			break;
    		$count++;
    	?>
    		<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    		<div class="entry"><?php echo $content ?></div>
    	<?php
    	}
    ?>

    The problem is , it display grandchildren too..
    How can I exclude grandchildren from being displayed ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter harrismc

    (@harrismc)

    I searched codex and I found only that exclude_tree can be used to hide grandchildren in conjunction with a ‘child_of’ value. But no details..

    Thread Starter harrismc

    (@harrismc)

    Found it
    This worked
    $mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID);

    Found it
    This worked
    $mypages = get_pages(‘child_of=’.$post->ID.’&sort_column=post_date&sort_order=desc&parent=’.$post->ID);

    I am very grateful that you are considerate enough to post the solution.

    This has totally solved my problem also.

    Hi there,

    Thanks for sharing! Something along the same lines worked for me too. Am sharing it here, in case it is handy for others:

    // Get the page's children (but not the grandchildren)
        $children = get_pages('child_of='.$post->ID.'&parent='.$post->ID);

    Thanks x x

    Oops, the sort order should be there too

    $children = get_pages('child_of='.$post->ID.'&sort_order=desc&parent='.$post->ID);

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_pages how to disable grandchildren’ is closed to new replies.