I've got the following code- I'm trying to get the last child page of a page with ID 4117. Here's my code thus far:
// WP_Query arguments
$args = array(
'post_parent' => '4117',
'posts_per_page' => '1',
'order' => 'DESC',
'orderby' => 'menu_order',
);
// The Query
$query = new WP_Query( $args );
$posts = $query->posts;
foreach($posts as $post) {
echo $post->post_title;
}
But it doesn't appear to do anything. Any clues as to what my issue may be?
I've got the following code- I'm trying to get the last child page of a page with ID 4117. Here's my code thus far:
// WP_Query arguments
$args = array(
'post_parent' => '4117',
'posts_per_page' => '1',
'order' => 'DESC',
'orderby' => 'menu_order',
);
// The Query
$query = new WP_Query( $args );
$posts = $query->posts;
foreach($posts as $post) {
echo $post->post_title;
}
But it doesn't appear to do anything. Any clues as to what my issue may be?
WP_Query
defaults to getting posts, not pages.
From the above reference page:
Display content based on post and page parameters. Remember that default
post_type
is only set to display posts but not pages.
This code:
// WP_Query arguments
$args = array(
'post_parent' => '4117',
'post_type' => 'page',
'posts_per_page' => '1',
'order' => 'DESC',
'orderby' => 'menu_order',
);
// The Query
$query = new WP_Query( $args );
$posts = $query->posts;
foreach ( $posts as $post ) {
echo $post->post_title;
}
...should do what you want.