diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 5bed9212b..6224ce0b8 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -1114,20 +1114,20 @@ function get_calendar($initial = true, $echo = true) { } $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); + $last_day = date('t', $unixmonth); // Get the next and previous month and year with at least one post - $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year + $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); - $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year + $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts - WHERE post_date > '$thisyear-$thismonth-01' - AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) + WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' AND post_type = 'post' AND post_status = 'publish' - ORDER BY post_date ASC + ORDER BY post_date ASC LIMIT 1"); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ @@ -1179,10 +1179,9 @@ function get_calendar($initial = true, $echo = true) { // Get days with posts $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) - FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' - AND YEAR(post_date) = '$thisyear' + FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' AND post_type = 'post' AND post_status = 'publish' - AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); + AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); if ( $dayswithposts ) { foreach ( (array) $dayswithposts as $daywith ) { $daywithpost[] = $daywith[0]; @@ -1199,9 +1198,8 @@ function get_calendar($initial = true, $echo = true) { $ak_titles_for_day = array(); $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom " ."FROM $wpdb->posts " - ."WHERE YEAR(post_date) = '$thisyear' " - ."AND MONTH(post_date) = '$thismonth' " - ."AND post_date < '".current_time('mysql')."' " + ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " + ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " ."AND post_type = 'post' AND post_status = 'publish'" ); if ( $ak_post_titles ) {