I have an array of IDs and I want to get that posts by WP_Quey()
$myarray = $ids;
$args = array( 'post__in' => $myarray);
// The Query
$the_query = new WP_Query( $args );
Its, Sort result by date But I want to sort it by $myarray items and first result would be first ID in $myarray
In WordPress 3.5 and up you can use
'orderby'=>'post__in'
then you must write this:I know, that my answer is too late, but i have to answer correctly.
As i tried
'orderby'=>'post__in'
:for example i have dynamically updated cookies, and i must to load products in recently viewed products block in order, that first product in this block must be last viewed.
OK.
I had ids 1720, 19626, 19173, 19188.
This string in output returned my products in order:
19626, 19188, 19173, 1720 and its not my order. This cause simply order parameter DESC by default
WP_Query
. And we have only one another chance –ASC
it…very sad answer by M H.My answer is simply clever:
we DO NOT NEED to ‘orderby’=>’post__in’
we have to get:
After it we do:
That’s it!
Properly transmitting the order: