Query children and parent title

I’m not entirely sure if I get your problem correctly, because of the “it’s not an option part”, but… You get children pages of page with ID = 2, so it looks like you want to display the title of that page. If so, then this code will solve your problem: <?php $args = array( … Read more

List the 5 most recent child pages

Assuming you know (or know how to get) the $id (as an integer) of the parent post, use the post_parent parameter: $albums = new WP_Query(array( ‘post_type’ => ‘gallery’, ‘posts_per_page’ => 6, ‘post_parent’ => $id )); Edit Based on this comment: I don’t know the parent post. I want to list the most recent child pages … Read more

Can’t change parent page

I was able to fix this problem only in phpMyAdmin. Shortly: find the child page in the table ‘wp_posts’ and change the value of ‘post_parent’ to 0 (zero). Step by step: Browse the table ‘wp_posts’, find the child page by title (post_title) or whatever else attribute. Be sure it isn’t a revision (check it in … Read more

Do not show child pages of child pages

You can do that with using the depth argument. I also created an array of your arguments for better readability. The depth argument accepts the following parameters: ‘depth’ (int) Number of levels in the hierarchy of pages to include in the generated list. Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and … Read more

Displaying child page content of a certain parent

This is a near duplicate of a number of questions here, but the “single random result” might make it somewhat distinct. $args = array( ‘post_type’ => ‘page’, ‘post_parent’ => $post->ID, ‘orderby’ => ‘rand’, ‘posts_per_page’ => 1, ‘no_found_rows’ => true ); $child = new WP_Query($args); var_dump($child->posts); You are telling WP_Query to pick 1) pages, 2) with … Read more

Load parent pages when there are no child pages

possible code: <?php $children = wp_list_pages(‘title_li=&child_of=”.$post->ID.”&echo=0&depth=1’); if ($children) { ?> <ul id=”three-menu”> <?php echo $children; ?> </ul> <?php } //ends (if($children)// elseif($post->post_parent) { //if no children, try to get parent page and show siblings pages including the page itself $siblings = wp_list_pages(‘title_li=&child_of=”.$post->post_parent.”&echo=0&depth=1’); if ($siblings) { ?> <ul id=”three-menu”> <?php echo $siblings; ?> </ul> <?php } … Read more