Wordpress - How do I get posts by multiple post ID's?
You can use get_posts()
as it takes the same arguments as WP_Query
.
To pass it the IDs, use 'post__in' => array(43,23,65)
(only takes arrays).
Something like:
$args = array(
'post__in' => array(43,23,65)
);
$posts = get_posts($args);
foreach ($posts as $p) :
//post!
endforeach;
I'd also set the post_type
and posts_per_page
just for good measure.
If you can't get the above to work, make sure you add post_type
:
$args = array(
'post_type' => 'pt_case_study',
'post__in' => array(2417, 2112, 784)
);
$posts = get_posts($args);