Overriding default calendar to show posts from a category
I'm trying to modify the default WP calendar (get_calendar()) so that it shows posts from a specific category and then use that as a shortcode.
Here's what I've done:
Copied across the get_calendar() function from the core (from wp-includes) into my child theme's functions.php file. In order to make it an 'independent' calendar, I changed the name of the get_calendar() function to osu_get_calendar() and have successfully hardcoded the calendar into my template using osu_get_calendar();
Now I'm trying to get my hands a bit dirtier and do the following:
1) Restrict the posts shown in the calendar to a specific category (while maintaining the previous and next navigation so visitors can search through those posts by month)
2) Make it into a shortcode so my client can essentially embed a calendar with posts from a category they choose at the bottom of their posts.
I'm stuck on 1) at the moment as it looks like I need to modify the SQL queries so that it pulls posts from a specific category. Looking at the code below from the get_calendar() function, how would I filter the posts pulled from the database so that they are from a specific category? There are other SQL queries in there, but hopefully someone can help me with this one for now:
$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'
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'
AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
AND post_type = 'post' AND post_status = 'publish'
ORDER BY post_date ASC
LIMIT 1");
Thanks,
osu