I am not getting anything, an empty page. Am I missing something?
Yes, you are.
$query->the_post()
does not display anything — it just moves the pointer/key in the posts array ($query->posts
) to the next one, and setups the global post data ($GLOBALS['post']
). So yes, in response to your answer, the_content()
would be what you would use to display the content of the current post in the loop.
But actually, you could simply use the page_id
parameter like so, to query a post of the page
type and having a specific ID:
$args = array(
// Instead of using post_type and post__in, you could simply do:
'page_id' => 1149,
);
Also, you should call wp_reset_postdata()
after your loop ends so that template tags (e.g. the_content()
and the_title()
) would use the main query’s current post again.
while ($query->have_posts()) {
$query->the_post();
the_content();
}
wp_reset_postdata();
And just so that you know, you could also use get_post()
and setup_postdata()
like so, without having to use the new WP_Query()
way:
//global $post; // uncomment if necessary
$post = get_post( 1149 );
setup_postdata( $post );
the_title();
the_content();
// ... etc.
wp_reset_postdata();