From 0b1292e1d2488202f05ca83db5e309bd8bed69dd Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 4 Mar 2009 22:28:45 +0000 Subject: [PATCH] Fix calendar widget when there are no posts. Optimize query. Props Denis-de-Bernardy. fixes #6442 git-svn-id: http://svn.automattic.com/wordpress/trunk@10708 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 6d46dce46..4a2e3fe35 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -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']);