Code Location: http://wp-priv-post-access.googlecode.com/svn/trunk//trunk
Browse
/
Download File
calendar-sql-hook.patch
--- wp-includes/general-template.php.bak	2009-06-11 08:04:20.000000000 +0800
+++ wp-includes/general-template.php	2009-07-19 15:04:35.000000000 +0800
@@ -967,9 +967,13 @@
 	if ( !is_array($cache) )
 		$cache = array();
 
+	//filters
+	$where = apply_filters('getcalendar_where', "WHERE post_type = 'post' AND post_status = 'publish'" );
+	$join = apply_filters('getcalendar_join', "");
+
 	// Quick check. If we have no posts at all, abort!
 	if ( !$posts ) {
-		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
+		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts $join $where LIMIT 1");
 		if ( !$gotsome ) {
 			$cache[ $key ] = '';
 			wp_cache_set( 'get_calendar', $cache, 'calendar' );
@@ -1008,16 +1012,14 @@
 
 	// 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
-		FROM $wpdb->posts
-		WHERE post_date < '$thisyear-$thismonth-01'
-		AND post_type = 'post' AND post_status = 'publish'
+		FROM $wpdb->posts $join $where
+		AND post_date < '$thisyear-$thismonth-01'
 			ORDER BY post_date DESC
 			LIMIT 1");
 	$next = $wpdb->get_row("SELECT	DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
-		FROM $wpdb->posts
-		WHERE post_date >	'$thisyear-$thismonth-01'
+		FROM $wpdb->posts $join $where
+		AND post_date >	'$thisyear-$thismonth-01'
 		AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
-		AND post_type = 'post' AND post_status = 'publish'
 			ORDER	BY post_date ASC
 			LIMIT 1");
 
@@ -1073,9 +1075,8 @@
 
 	// Get days with posts
 	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
-		FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
+		FROM $wpdb->posts $join $where AND MONTH(post_date) = '$thismonth'
 		AND YEAR(post_date) = '$thisyear'
-		AND post_type = 'post' AND post_status = 'publish'
 		AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
 	if ( $dayswithposts ) {
 		foreach ( (array) $dayswithposts as $daywith ) {
@@ -1093,10 +1094,9 @@
 	$ak_titles_for_day = array();
 	$ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
 		."FROM $wpdb->posts "
-		."WHERE YEAR(post_date) = '$thisyear' "
+		."$join $where AND YEAR(post_date) = '$thisyear' "
 		."AND MONTH(post_date) = '$thismonth' "
 		."AND post_date < '".current_time('mysql')."' "
-		."AND post_type = 'post' AND post_status = 'publish'"
 	);
 	if ( $ak_post_titles ) {
 		foreach ( (array) $ak_post_titles as $ak_post_title ) {