Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Get calendar custom post type #14

Closed
wants to merge 3 commits into from

3 participants

Alisher Agzamov Dan Dascalescu Andrew Nacin
Alisher Agzamov

With the addition of the third argument to the function get_calendar(), we can use this function with any custom post types.

added some commits July 11, 2012
Dan Dascalescu

@woodpeople Please bug @nacin to update the repo's description to mention that this is a read-only mirror and commits should be submitted at http://core.trac.wordpress.org/. Right now a lot of people waste their time here with pull requests.

Andrew Nacin
Owner

This is a duplicate of http://core.trac.wordpress.org/ticket/16173. Please feel free to comment there, and post a patch if you think that is appropriate.

Andrew Nacin nacin closed this September 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Jul 11, 2012
get_calendar() - custom post type 1076a89
Remove unused var cache 5d206c2
Add param post_type info c207cef
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 7 deletions. Show diff stats Hide diff stats

  1. 14  wp-includes/general-template.php
14  wp-includes/general-template.php
@@ -1070,11 +1070,11 @@ function calendar_week_mod($num) {
1070 1070
  *
1071 1071
  * @param bool $initial Optional, default is true. Use initial calendar names.
1072 1072
  * @param bool $echo Optional, default is true. Set to false for return.
  1073
+ * @param string $post_type Optional, default is post. Set to your custom post type.
1073 1074
  */
1074  
-function get_calendar($initial = true, $echo = true) {
  1075
+function get_calendar($initial = true, $echo = true, $post_type = 'post') {
1075 1076
 	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1076 1077
 
1077  
-	$cache = array();
1078 1078
 	$key = md5( $m . $monthnum . $year );
1079 1079
 	if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
1080 1080
 		if ( is_array($cache) && isset( $cache[ $key ] ) ) {
@@ -1092,7 +1092,7 @@ function get_calendar($initial = true, $echo = true) {
1092 1092
 
1093 1093
 	// Quick check. If we have no posts at all, abort!
1094 1094
 	if ( !$posts ) {
1095  
-		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  1095
+		$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = '{$post_type}' AND post_status = 'publish' LIMIT 1");
1096 1096
 		if ( !$gotsome ) {
1097 1097
 			$cache[ $key ] = '';
1098 1098
 			wp_cache_set( 'get_calendar', $cache, 'calendar' );
@@ -1133,13 +1133,13 @@ function get_calendar($initial = true, $echo = true) {
1133 1133
 	$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1134 1134
 		FROM $wpdb->posts
1135 1135
 		WHERE post_date < '$thisyear-$thismonth-01'
1136  
-		AND post_type = 'post' AND post_status = 'publish'
  1136
+		AND post_type = '{$post_type}' AND post_status = 'publish'
1137 1137
 			ORDER BY post_date DESC
1138 1138
 			LIMIT 1");
1139 1139
 	$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1140 1140
 		FROM $wpdb->posts
1141 1141
 		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1142  
-		AND post_type = 'post' AND post_status = 'publish'
  1142
+		AND post_type = '{$post_type}' AND post_status = 'publish'
1143 1143
 			ORDER BY post_date ASC
1144 1144
 			LIMIT 1");
1145 1145
 
@@ -1193,7 +1193,7 @@ function get_calendar($initial = true, $echo = true) {
1193 1193
 	// Get days with posts
1194 1194
 	$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1195 1195
 		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
1196  
-		AND post_type = 'post' AND post_status = 'publish'
  1196
+		AND post_type = '{$post_type}' AND post_status = 'publish'
1197 1197
 		AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
1198 1198
 	if ( $dayswithposts ) {
1199 1199
 		foreach ( (array) $dayswithposts as $daywith ) {
@@ -1213,7 +1213,7 @@ function get_calendar($initial = true, $echo = true) {
1213 1213
 		."FROM $wpdb->posts "
1214 1214
 		."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
1215 1215
 		."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
1216  
-		."AND post_type = 'post' AND post_status = 'publish'"
  1216
+		."AND post_type = '{$post_type}' AND post_status = 'publish'"
1217 1217
 	);
1218 1218
 	if ( $ak_post_titles ) {
1219 1219
 		foreach ( (array) $ak_post_titles as $ak_post_title ) {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.