Fix calendar widget when there are no posts. Optimize query. Props Denis-de-Bernardy. fixes #6442

git-svn-id: https://develop.svn.wordpress.org/trunk@10708 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2009-03-04 22:28:45 +00:00
parent b5d7564f50
commit d6978c424f
1 changed files with 6 additions and 3 deletions

View File

@ -930,14 +930,17 @@ function get_calendar($initial = true) {
if ( !is_array($cache) )
$cache = array();
ob_start();
// Quick check. If we have no posts at all, abort!
if ( !$posts ) {
$gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
if ( !$gotsome )
$gotsome = $wpdb->get_var("SELECT 1 FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
if ( !$gotsome ) {
$cache[ $key ] = '';
wp_cache_set( 'get_calendar', $cache, 'calendar' );
return;
}
}
ob_start();
if ( isset($_GET['w']) )
$w = ''.intval($_GET['w']);