Wordpress - Order by & include array by specific post ids
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => 4,
'orderby' => 'post__in',
'post__in' => array(883, 563, 568, 106)
);
Using post__in
within the orderby
value it will honour the order of the array of IDs passed in post__in
use post__in
key instead of include
to get posts from the specific post ids.
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => 4,
'orderby' => 'ID',
'post__in' => array(883, 563, 568, 106),
);
And to order posts
by the given posts ids
, you can use the following array.
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => 4,
'orderby' => 'post__in',
'post__in' => array(883, 563, 568, 106),
);