WP_Query for showing specific post by id

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.

Checking out the SQL query

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.

Helpful docs

It’s also helpful to look at the Developer’s Handbook:


and in some cases the old Codex: