Make WordPress Core

Ticket #18836: 18836.diff

File 18836.diff, 976 bytes (added by MisdaX, 10 years ago)

first attempt - passes all phpunit standard tests

  • wp-includes/query.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    33833383
    33843384                if ( ! empty($groupby) )
    33853385                        $groupby = 'GROUP BY ' . $groupby;
    3386                 if ( !empty( $orderby ) )
     3386                if ( !empty( $orderby ) ) {
    33873387                        $orderby = 'ORDER BY ' . $orderby;
     3388
     3389                        /**
     3390                         * Replace the standard MySQL rand() with an improved version.
     3391                         *
     3392                         * @link https://core.trac.wordpress.org/ticket/18836
     3393                         * @link http://stackoverflow.com/a/25882872
     3394                         */
     3395                        if ( 0 === strcasecmp( $orderby, 'ORDER BY RAND()' ) ) {
     3396                                $orderby = "AND ( rand() <= " . $q['posts_per_page'] . " * 2 / ( SELECT count(*) FROM $wpdb->posts $join WHERE 1=1 $where $groupby ) )";
     3397                        }
     3398                }
    33883399
    33893400                $found_rows = '';
    33903401                if ( !$q['no_found_rows'] && !empty($limits) )