Category specific months list in sidebar.php

you can use getarchives_where filter to get archives by category

add_filter( 'getarchives_where', 'my_archives_filter_function', 10, 2 );

// your filter function replace YOUR CATEGORY ID with category term id e.g(3)
function my_archives_filter_function($where) {
   global $wpdb;
   $where ." AND $wpdb->posts.ID IN (SELECT $wpdb->posts.ID FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id = 'YOUR CATEGORY ID')";
   return $where;
}

now call wp_get_archives();

Leave a Comment