I’ve got a string with post ID’s: 43,23,65
.
I was hoping I could use get_posts()
and use the string with ID’s as an argument.
But I can’t find any functions for retrieving multiple posts by ID.
Do I really have to do a WP_query
?
I’ve also seen someone mention using tag_in
– but I can’t find any documentation on this.
You can use
get_posts()
as it takes the same arguments asWP_Query
.To pass it the IDs, use
'post__in' => array(43,23,65)
(only takes arrays).Something like:
I’d also set the
post_type
andposts_per_page
just for good measure.If you can’t get the above to work, make sure you add
post_type
:If you want to get all the posts by their IDs (regardless of post type) use this:
Or even shorter: