Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#13729 closed enhancement

Post Query should be able to order by specific order passed in "post__in" — at Initial Version

Reported by: jakemgold Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: minor Version: 3.0
Component: Query Keywords: has-patch needs-codex
Focuses: Cc:


Post queries can specify the posts to retrieve by passing an array of post IDs to the "postin" parameter.

There is no built in method for sorting those posts by the order specified. In fact, I would argue that when using "postin", the post query should, by default, order the posts in the same order specified in that array (I think this is the expected behavior by the developer).

Many custom themes allow the developer to specifically designate featured posts, controlling the order in which they appear. Many of these themes are forced to make independent queries for each post or execute an atypical loop by calling the result by ID (the post array's key). The ability to "fetch", properly order, and execute a standard loop for a specific set of posts in a specific order would reduce overhead and complexity in these situations.

I've developed a plug-in that does this as a workaround:


The 3.0+ specific code in there is *very* simple. It would be even more simple to do in base code (just another "case" in the orderby switch part of the query builder). In fact, I intend to submit a patch after 3.0 is released.

My plug-in provides the framework for the SQL to do this.

Change History (0)

Note: See TracTickets for help on using tickets.