WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Orderby = none not working

I want to use $query = new WP_Query( 'post__in' => array( 2, 5, 12, 14, 20 ) ) ); to retrieve posts by ID, I do and the result ordered by publish date but I want to retrieve in same of IDs in this example in this order: 2, 5, 12, 14, 20

share|improve this question

marked as duplicate by Otto, Brian Fegter, Rarst Oct 2 '12 at 21:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

In WordPress 3.5, you'll be able to do this with the 'orderby' parameter set to 'post__in'.

Until then, this question is basically identical to another one, which I wrote an answer for already: Orderby = none not working

share|improve this answer

In your example you can order by ID ascending to get those results:

$query = new WP_Query( 
        'post__in' => array( 2, 5, 12, 14, 20 ),
        'orderby' => 'ID',
        'order' => 'ASC'

see WP_Query in Codex for the full list of arguments.

share|improve this answer
this is not solution but in this case ignore 2, 5, 12, 14, 20 – Ehsan Oct 1 '12 at 15:09
then edit your question to be more specific about what you're trying to achieve. – Milo Oct 1 '12 at 15:10
I said that I want ordering by 2, 5, 12, 14, 20 ... excuse me for my bad english – Ehsan Oct 1 '12 at 15:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.