but it just shows the first post, I need to show three posts, please help me
$the_query = new WP_Query(array(
'p' => '272 282 292',));
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();?>
// Do Stuff
endwhile;
endif;
// Reset Post Data
wp_reset_postdata();
but it just shows the first post, I need to show three posts, please help me
$the_query = new WP_Query(array(
'p' => '272 282 292',));
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();?>
// Do Stuff
endwhile;
endif;
// Reset Post Data
wp_reset_postdata();
For multiple post IDs, in WP_Query
arguments, we can use:
'post__in' => [ 272, 282, 292 ],
but for a single post ID it's:
'p' => 123,
Note that the default post type is post
.
It's informative to checkout the generated SQL query of WP_Query
.
Try e.g. in the wp-cli shell:
wp> $q = new WP_Query( [ 'post__in' => [ 272, 282, 292 ] ] );
wp> echo $q->request;
That way you can make sure it's generating what you need.
Compare e.g. the post__in
and the p
case.
It's also helpful to look at the Developer's Handbook:
https://developer.wordpress/reference/classes/wp_query/
and in some cases the old Codex:
https://codex.wordpress/Class_Reference/WP_Query