Ticket #8351: patch.diff

File patch.diff, 4.2 KB (added by vladimir_kolesnikov, 3 years ago)

Patch for the Ticket #8351

  • wp-includes/general-template.php

     
    750750        $output = ''; 
    751751 
    752752        if ( 'monthly' == $type ) { 
    753                 $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"; 
     753                $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"; 
    754754                $key = md5($query); 
    755755                $cache = wp_cache_get( 'wp_get_archives' , 'general'); 
    756756                if ( !isset( $cache[ $key ] ) ) { 
     
    771771                        } 
    772772                } 
    773773        } elseif ('yearly' == $type) { 
    774                 $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"; 
     774                $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"; 
    775775                $key = md5($query); 
    776776                $cache = wp_cache_get( 'wp_get_archives' , 'general'); 
    777777                if ( !isset( $cache[ $key ] ) ) { 
     
    792792                        } 
    793793                } 
    794794        } elseif ( 'daily' == $type ) { 
    795                 $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"; 
     795                $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"; 
    796796                $key = md5($query); 
    797797                $cache = wp_cache_get( 'wp_get_archives' , 'general'); 
    798798                if ( !isset( $cache[ $key ] ) ) { 
     
    913913        ob_start(); 
    914914        // Quick check. If we have no posts at all, abort! 
    915915        if ( !$posts ) { 
    916                 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); 
     916                $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); 
    917917                if ( !$gotsome ) 
    918918                        return; 
    919919        } 
     
    947947        $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 
    948948 
    949949        // Get the next and previous month and year with at least one post 
    950         $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 
     950        $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 
    951951                FROM $wpdb->posts 
    952952                WHERE post_date < '$thisyear-$thismonth-01' 
    953953                AND post_type = 'post' AND post_status = 'publish' 
    954954                        ORDER BY post_date DESC 
    955955                        LIMIT 1"); 
    956         $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 
     956        $last_day = date('t'); 
     957        $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 
    957958                FROM $wpdb->posts 
    958                 WHERE post_date >       '$thisyear-$thismonth-01' 
    959                 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 
     959                WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 
    960960                AND post_type = 'post' AND post_status = 'publish' 
    961961                        ORDER   BY post_date ASC 
    962962                        LIMIT 1"); 
     
    10111011 
    10121012        // Get days with posts 
    10131013        $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 
    1014                 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' 
    1015                 AND YEAR(post_date) = '$thisyear' 
     1014                FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' 
    10161015                AND post_type = 'post' AND post_status = 'publish' 
    10171016                AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); 
    10181017        if ( $dayswithposts ) { 
     
    10311030        $ak_titles_for_day = array(); 
    10321031        $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " 
    10331032                ."FROM $wpdb->posts " 
    1034                 ."WHERE YEAR(post_date) = '$thisyear' " 
    1035                 ."AND MONTH(post_date) = '$thismonth' " 
     1033                ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " 
    10361034                ."AND post_date < '".current_time('mysql')."' " 
    10371035                ."AND post_type = 'post' AND post_status = 'publish'" 
    10381036        );