[wp-trac] [WordPress Trac] #13729: Post Query should be able to order by specific order passed in "post__in"

WordPress Trac wp-trac at lists.automattic.com
Wed Sep 5 22:01:50 UTC 2012


#13729: Post Query should be able to order by specific order passed in "post__in"
-----------------------------------+-----------------------------
 Reporter:  jakemgold              |       Owner:  jakemgold
     Type:  enhancement            |      Status:  accepted
 Priority:  normal                 |   Milestone:  Future Release
Component:  Query                  |     Version:  3.0
 Severity:  minor                  |  Resolution:
 Keywords:  2nd-opinion has-patch  |
-----------------------------------+-----------------------------
Description changed by scribu:

Old description:

> 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:
>
> http://wordpress.org/extend/plugins/sort-query-by-post-in/
>
> 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.

New description:

 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:

 http://wordpress.org/extend/plugins/sort-query-by-post-in/

 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.

--

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13729#comment:16>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list