Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Get calendar custom post type #14

Closed
wants to merge 3 commits into from

3 participants

@woodpeople

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

Alisher Agzamov added some commits
@dandv

@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.

@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.

@nacin nacin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2012
  1. get_calendar() - custom post type

    Alisher Agzamov authored
  2. Remove unused var cache

    Alisher Agzamov authored
  3. Add param post_type info

    Alisher Agzamov authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 7 deletions.
  1. +7 −7 wp-includes/general-template.php
View
14 wp-includes/general-template.php
@@ -1070,11 +1070,11 @@ function calendar_week_mod($num) {
*
* @param bool $initial Optional, default is true. Use initial calendar names.
* @param bool $echo Optional, default is true. Set to false for return.
+ * @param string $post_type Optional, default is post. Set to your custom post type.
*/
-function get_calendar($initial = true, $echo = true) {
+function get_calendar($initial = true, $echo = true, $post_type = 'post') {
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
- $cache = array();
$key = md5( $m . $monthnum . $year );
if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
if ( is_array($cache) && isset( $cache[ $key ] ) ) {
@@ -1092,7 +1092,7 @@ function get_calendar($initial = true, $echo = true) {
// 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 WHERE post_type = '{$post_type}' AND post_status = 'publish' LIMIT 1");
if ( !$gotsome ) {
$cache[ $key ] = '';
wp_cache_set( 'get_calendar', $cache, 'calendar' );
@@ -1133,13 +1133,13 @@ function get_calendar($initial = true, $echo = true) {
$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'
+ AND post_type = '{$post_type}' AND post_status = 'publish'
ORDER BY post_date DESC
LIMIT 1");
$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
- AND post_type = 'post' AND post_status = 'publish'
+ AND post_type = '{$post_type}' AND post_status = 'publish'
ORDER BY post_date ASC
LIMIT 1");
@@ -1193,7 +1193,7 @@ function get_calendar($initial = true, $echo = true) {
// Get days with posts
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
- AND post_type = 'post' AND post_status = 'publish'
+ AND post_type = '{$post_type}' AND post_status = 'publish'
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
if ( $dayswithposts ) {
foreach ( (array) $dayswithposts as $daywith ) {
@@ -1213,7 +1213,7 @@ function get_calendar($initial = true, $echo = true) {
."FROM $wpdb->posts "
."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'"
+ ."AND post_type = '{$post_type}' AND post_status = 'publish'"
);
if ( $ak_post_titles ) {
foreach ( (array) $ak_post_titles as $ak_post_title ) {
Something went wrong with that request. Please try again.