Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP_Query with an array of IDs order by array

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

like image 541
Ehsan Avatar asked Mar 07 '14 04:03

Ehsan


1 Answers

In Wordpress 3.5 and up you can use 'orderby'=>'post__in' then you must write this:

$myarray = $ids;    
$args = array('post__in'=> $myarray, 'orderby'=>'post__in');
// The Query
$the_query = new WP_Query( $args );
like image 88
M H Avatar answered Oct 04 '22 04:10

M H