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!

Code Snippet:

<?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');
?>

Posted in Posts