WordPress.org

Make WordPress Core

Ticket #18832: 18832.diff

File 18832.diff, 2.9 KB (added by tar.gz, 7 years ago)

patch for wp_get_archives in wp-includes/general-template.php

  • wp-includes/general-template.php

     
    863863                'type' => 'monthly', 'limit' => '',
    864864                'format' => 'html', 'before' => '',
    865865                'after' => '', 'show_post_count' => false,
    866                 'echo' => 1
     866                'echo' => 1, 'order' => 'DESC'
    867867        );
    868868
    869869        $r = wp_parse_args( $args, $defaults );
     
    903903        $output = '';
    904904
    905905        if ( 'monthly' == $type ) {
    906                 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
     906                $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
    907907                $key = md5($query);
    908908                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    909909                if ( !isset( $cache[ $key ] ) ) {
     
    925925                        }
    926926                }
    927927        } elseif ('yearly' == $type) {
    928                 $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit";
     928                $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
    929929                $key = md5($query);
    930930                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    931931                if ( !isset( $cache[ $key ] ) ) {
     
    946946                        }
    947947                }
    948948        } elseif ( 'daily' == $type ) {
    949                 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";
     949                $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
    950950                $key = md5($query);
    951951                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    952952                if ( !isset( $cache[ $key ] ) ) {
     
    969969                }
    970970        } elseif ( 'weekly' == $type ) {
    971971                $week = _wp_mysql_week( '`post_date`' );
    972                 $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` DESC $limit";
     972                $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
    973973                $key = md5($query);
    974974                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    975975                if ( !isset( $cache[ $key ] ) ) {