WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2014 03:51:24 AM (7 years ago)
Author:
wonderboymusic
Message:

Ordering by RAND():

The shortcode callbacks for gallery and playlist check for 'RAND' == $atts['order'], which isn't a valid value for order. Remove those checks and update the docs.

In WP_Query, if the value of orderby is rand, order is irrelevant and should be unset.

Adds unit tests.

Fixes #29629.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r29658 r29760  
    27962796        $where .= $search . $whichauthor . $whichmimetype;
    27972797
     2798        $rand = ( isset( $q['orderby'] ) && 'rand' === $q['orderby'] );
    27982799        if ( ! isset( $q['order'] ) ) {
    2799             $q['order'] = 'DESC';
     2800            $q['order'] = $rand ? '' : 'DESC';
    28002801        } else {
    2801             $q['order'] = $this->parse_order( $q['order'] );
     2802            $q['order'] = $rand ? '' : $this->parse_order( $q['order'] );
    28022803        }
    28032804
     
    28502851
    28512852                if ( empty( $orderby ) ) {
    2852                     $orderby = "$wpdb->posts.post_date ".$q['order'];
    2853                 } else {
     2853                    $orderby = "$wpdb->posts.post_date " . $q['order'];
     2854                } elseif ( ! empty( $q['order'] ) ) {
    28542855                    $orderby .= " {$q['order']}";
    28552856                }
Note: See TracChangeset for help on using the changeset viewer.