Weird child page behavior
-
Tried to post this in WP-Advanced, but couldn’t so posting it here. I am having the weirdest problem I have ever seen on WP. It’s so weird that I haven’t seen it on any post, and I’ve been googling it for about three hours. I can’t link you because it’s a client site, but I’ll write down the exact setup here.
I have 4 or 5 main pages, all with subpages. One of these main pages is called About (ID is 2), and it has 5 subpages, like so:
- About
- The Designer
- The Services
- NDA
- Recent Work
- Quote
On the sidebar for the pages, I have this code to show either the subpages or the sibling pages:
<?php $children = get_children("post_parent=" . $post->ID ); if( $children ) { $output = wp_list_pages('title_li=&child_of=' .$post->ID. '&hierarchical=1&depth=1&echo=0'); } else { $output = wp_list_pages('title_li=&child_of=' .$post->post_parent. '&hierarchical=1&depth=1&echo=0'); } if($output) { ?> <li> <ul class="submenu"> <?php print $output; ?> </ul> </li> <?php } ?>Now, it works fantastically on every other page, except for 2 pages that are children of About.
So I thought to myself that there must be a problem with the code somewhere, so I placed a wp_list_pages function with the ID of the About instead of $post->post_parent. It worked great. So, I thought to go back to the root and see if it’s seeing its parent well. I placed this code in one of the pages in which the submenu doesn’t display (page ID is 6):
<?php $parent_title = get_the_title($post->post_parent); echo $parent_title;?> <?php $parent_id = get_the_id($post->post_parent); echo $parent_id;?>And, the result for that is : About6.
I went in and checked if it’s a child page in the WP admin, and it is. I’ve resaved it about 10 times, and it still displays the same.
I don’t know what the hell is going on… Help? Please? I don’t know where to look anymore, and I’m pretty sure that the initial code is correct because I’ve used it before on other sites.
The topic ‘Weird child page behavior’ is closed to new replies.