WordPress.org

Make WordPress Core

Changeset 21610


Ignore:
Timestamp:
08/24/2012 08:50:22 PM (8 years ago)
Author:
nacin
Message:

Add 'order' to wp_get_archives(). props tar.gz. fixes #18832.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r21597 r21610  
    870870        'format' => 'html', 'before' => '',
    871871        'after' => '', 'show_post_count' => false,
    872         'echo' => 1
     872        'echo' => 1, 'order' => 'DESC',
    873873    );
    874874
     
    883883        $limit = ' LIMIT '.$limit;
    884884    }
     885
     886    $order = strtoupper( $order );
     887    if ( $order !== 'ASC' )
     888        $order = 'DESC';
    885889
    886890    // this is what will separate dates on weekly archive links
     
    910914
    911915    if ( 'monthly' == $type ) {
    912         $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";
     916        $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";
    913917        $key = md5($query);
    914918        $cache = wp_cache_get( 'wp_get_archives' , 'general');
     
    932936        }
    933937    } elseif ('yearly' == $type) {
    934         $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";
     938        $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";
    935939        $key = md5($query);
    936940        $cache = wp_cache_get( 'wp_get_archives' , 'general');
     
    953957        }
    954958    } elseif ( 'daily' == $type ) {
    955         $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";
     959        $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";
    956960        $key = md5($query);
    957961        $cache = wp_cache_get( 'wp_get_archives' , 'general');
     
    976980    } elseif ( 'weekly' == $type ) {
    977981        $week = _wp_mysql_week( '`post_date`' );
    978         $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";
     982        $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";
    979983        $key = md5($query);
    980984        $cache = wp_cache_get( 'wp_get_archives' , 'general');
Note: See TracChangeset for help on using the changeset viewer.