WordPress.org

Make WordPress Core

Changeset 10602


Ignore:
Timestamp:
02/19/2009 10:53:19 PM (11 years ago)
Author:
ryan
Message:

Better archives and calendar queries. Props vladimir_kolesnikov. fixes #8351

File:
1 edited

Legend:

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

    r10558 r10602  
    761761
    762762    if ( 'monthly' == $type ) {
    763         $query = "SELECT DISTINCT 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";
     763        $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";
    764764        $key = md5($query);
    765765        $cache = wp_cache_get( 'wp_get_archives' , 'general');
     
    782782        }
    783783    } elseif ('yearly' == $type) {
    784         $query = "SELECT DISTINCT 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";
     784        $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";
    785785        $key = md5($query);
    786786        $cache = wp_cache_get( 'wp_get_archives' , 'general');
     
    803803        }
    804804    } elseif ( 'daily' == $type ) {
    805         $query = "SELECT DISTINCT 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";
     805        $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";
    806806        $key = md5($query);
    807807        $cache = wp_cache_get( 'wp_get_archives' , 'general');
     
    928928    // Quick check. If we have no posts at all, abort!
    929929    if ( !$posts ) {
    930         $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
     930        $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
    931931        if ( !$gotsome )
    932932            return;
     
    962962
    963963    // Get the next and previous month and year with at least one post
    964     $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
     964    $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    965965        FROM $wpdb->posts
    966966        WHERE post_date < '$thisyear-$thismonth-01'
     
    968968            ORDER BY post_date DESC
    969969            LIMIT 1");
    970     $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
     970    $last_day = date('t');
     971    $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
    971972        FROM $wpdb->posts
    972         WHERE post_date >   '$thisyear-$thismonth-01'
    973         AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
     973        WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
    974974        AND post_type = 'post' AND post_status = 'publish'
    975975            ORDER   BY post_date ASC
     
    10261026    // Get days with posts
    10271027    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    1028         FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
    1029         AND YEAR(post_date) = '$thisyear'
     1028        FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
    10301029        AND post_type = 'post' AND post_status = 'publish'
    10311030        AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
     
    10461045    $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
    10471046        ."FROM $wpdb->posts "
    1048         ."WHERE YEAR(post_date) = '$thisyear' "
    1049         ."AND MONTH(post_date) = '$thismonth' "
     1047        ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
    10501048        ."AND post_date < '".current_time('mysql')."' "
    10511049        ."AND post_type = 'post' AND post_status = 'publish'"
Note: See TracChangeset for help on using the changeset viewer.