Hacking the WordPress Calendar Widget

I’m fine-tuning my WordPress multisite blog installation.

A blog is designed to look into the past, not the future. While it was a simple matter to turn MovableType into a rudimentary course management system by simply post-dating blog entries, WordPress goes out of its way to hide future content.

I use the plugin “No Future Posts” to make future-dated posts appear on the site, but the calendar widget is designed so that it hides future content.

Somewhere on the internet I found the solution — hack the file wp-includes/general-template.php and change the behavior of the calendar widget.

I implemented that solution, and saw it working beautifully. I remember thinking to myself, “I ought to write this solution down, because as soon as I upgrade WordPress, these changes will be overwritten.” I think I settled for just saving a copy of the modified file.

I just upgraded WordPress yesterday afternoon, and the changes were overwritten, and I it was more of a bother than it should have been to find that modified file.

So here that solution is again, with a narrative explaining what it’s all about.

// Get days with posts
// $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
//     FROM $wpdb->posts WHERE 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);
   $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
       FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
       AND YEAR(post_date) = '$thisyear'
       AND post_type = 'post' AND post_status = 'publish'
       ", ARRAY_N);
// ** Simple fix to force calendars to show, not hide, future events.

By the way, it took me WAY too long to get the spacing right on that code sample. In WordPress, the “code” tag doesn’t do what I thought it would do — preserve the spacing, without trimming extra whitespace.