[wp-trac] [WordPress Trac] #19040: get_posts() expects invalid 'orderby' arguments + suggestion

WordPress Trac wp-trac at lists.automattic.com
Wed Nov 2 01:03:39 UTC 2011


#19040: get_posts() expects invalid 'orderby' arguments + suggestion
-------------------------------------+-----------------------
 Reporter:  abrcam                   |       Owner:
     Type:  defect (bug)             |      Status:  reopened
 Priority:  normal                   |   Milestone:
Component:  Query                    |     Version:  3.2.1
 Severity:  normal                   |  Resolution:
 Keywords:  close reporter-feedback  |
-------------------------------------+-----------------------
Changes (by abrcam):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 What I'm trying to say is that line 2332 above the switch() will cause
 those elements to never reach the switch() and they will get excluded
 altogether -- renaming never happens for elements not in `$allowed_keys`
 (which does not have the proper column names):
 http://core.trac.wordpress.org/browser/tags/3.2.1/wp-
 includes/query.php#L2332

 Thus the query that is built at line 2623 does not (always) include all
 the mentioned orderby columns and hence the query results are in an
 unexpected order, which is what I've reported.

 The output I mentioned is from an actual print/debug of `$this->request`
 at line 2623. Have you tried my example?

 {{{
         $images = get_children(array(
                 'post_type' => 'attachment',
                 'post_mime_type' => 'image',
                 'post_parent' => get_the_ID(),
                 'orderby' => 'menu_order post_date',
                 'order' => 'ASC',
                 ), ARRAY_A);
 }}}

 which yields `$this->request` at line 2623 to be equal to:

 {{{
 " SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_parent =
 172  AND (post_mime_type LIKE 'image/%')  AND wp_posts.post_type =
 'attachment' AND (wp_posts.post_status <> 'trash' AND wp_posts.post_status
 <> 'auto-draft')  ORDER BY menu_order ASC "
 }}}

 Note the missing order by `post_date`.

 I am reopening this ticket but will not insist further if it gets closed
 again as "invalid".

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


More information about the wp-trac mailing list