Post Query should be able to order by specific order passed in "post__in" — at Version 16
|Reported by:||jakemgold||Owned by:||jakemgold|
Description (last modified by scribu)
Post queries can specify the posts to retrieve by passing an array of post IDs to the post__in parameter.
There is no built in method for sorting those posts by the order specified. In fact, I would argue that when using post__in, 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 (18)
- Keywords 2nd-opinion added; post__in custom query orderby removed
- Milestone changed from 3.1 to Future Release
comment:7 @jakemgold — 4 years ago
- Keywords has-patch added
- Resolution set to fixed
- Status changed from new to closed
- Version changed from 3.0 to 3.2
- Resolution fixed deleted
- Status changed from closed to reopened
- Version changed from 3.2 to 3.0
comment:10 @jakemgold — 4 years ago
- Owner changed from ryan to dd32
- Status changed from reopened to reviewing
comment:14 @jakemgold — 3 years ago
- Owner set to jakemgold
- Status changed from reviewing to accepted