Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

wp_list_pages doesn't acknowledge parent page WordPress


I have a theme-provided widget that lists the sub-pages of the current page. It's simply a widget wrapping the wp_list_pages function. I've also used that raw function elsewhere in my templates, and it's worked fine.

It suddenly stopped working. I lost track of what created the problem, so I've had trouble backtracking. As of now, regardless of what page I visit, it presents only the top-tier items. It is as if the parent/child relationships of my pages no longer exist. I've double-checked and the still look fine. Sub-pages are related to their parents via the Page Attributes > Parent dropdown.

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php endwhile; endif; ?>

The above code always presents the top-level page items, even when it is used on a sub-page.

Any help is appreciated.

Answers (4)


Keith Pointon answers:

Ok, I'm not sure why that is showing the top level pages, but WordPress has a workaround to show a list of sub-pages on the codex, go here:

[[LINK href=""]]List subpages even if on a subpage[[/LINK]]

And it should give you everything you need. I've used this code a few times and it works very well.

if($post->post_parent) {
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
$titlenamer = get_the_title($post->post_parent);

else {
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$titlenamer = get_the_title($post->ID);
if ($children) { ?>

<h2> <? echo $titlenamer ?> </h2>
<?php echo $children; ?>

<?php } ?>


Denzel Chia answers:

Try putting

global $post;

Before wp_list_pages


Ivaylo Draganov answers:

There's probably something modifying the page query and thus changing the $post variable. But I agree with Oleg Butuzov that there's little we can do without direct debugging. You can of course try the usual practice:

* switch to default theme and test with it
* if the problem persists disable all plugins, start enabling one by one and check each time.
* check your templates for a <em>query_posts</em> anywhere before the call to <em>wp_list_pages()</em>.


Oleg Butuzov answers:

Sorry but this issue should be resolved n normal enviropment. one - developer and access to the scripts. Else you will waist much more time.