raeq raeq - 1 year ago 102
PHP Question

How to show only child pages of a Sub Child Page in WordPress?

So, I have a page structure in place that kind of looks like this

- New York
- Restaurant #1
- Dinner Menu
- Lunch Menu
- Restaurant #2
- Dinner Menu
- Lunch Menu

So when I am lets say the Restaurant #1 page, I want it show all the child pages of Restaurant #1 only. Unfortunately my current code base is returning all the Child pages of New York instead.

Here's my code:

if ( is_page() ) {
$children = wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->post_parent.'&echo=0');
$children = wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->ID.'&echo=0');

if ($children) {
echo $children;


Answer Source

Got it working. Here's how:

<? $pages = get_pages('child_of='.$post->ID.'&sort_column=post_title'); 
$count = 0; 
foreach($pages as $page){ ?>
    <a href="<? echo get_page_link($page->ID) ?>"><? echo$page->post_title?></a>
<? } 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download