Order posts using a custom array

I have an array of post ids which I’m passing to query_posts using ‘post__in’.

My question is how can I use the order from my array rather than ordering by ‘date’ etc?

Related posts

Leave a Reply

1 comment

  1. You would need to build your own query and pass it to query_posts i.e.

    if your array of post ids is:

    array (10,21,1)   // corresponding to post ids. 
    

    then you can query this way:

    select * from wp_posts where `ID` in (10, 21, 2)
    order by field(ID,10,21,2)
    

    This will give you a result set in the order of your post ids array.

    HTH