X

Retrieve Last Year Archives Only

This snippet retrieves and echoes only last year archives. It could be useful if you want to make collapsing/expanding archives by year.

Just inserts this snippet in your theme where you want to display archives.
You might want to tune the wp_get_archives options as you want!

<?php
function filter_last_year_archives($where_clause) {
	$year = date('Y') - 1;
    	return $where_clause." AND post_date LIKE '%".$year."%'";
}
add_filter('getarchives_where','filter_last_year_archives');
wp_get_archives('type=monthly&show_post_count=true&echo=1');
remove_filter('getarchives_where','filter_last_year_archives');
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!