Given the page id, check if it has children

The example from the WP codex for get_page_children does what you are looking for with a page titled “Portfolio”: $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array(‘post_type’ => ‘page’, ‘posts_per_page’ => ‘-1’)); // Get the page as an Object $portfolio = get_page_by_title(‘Portfolio’); // Filter through all pages and find Portfolio’s children $portfolio_children = get_page_children( $portfolio->ID, $all_wp_pages … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)