Ran into this problem in a project but never found a solution online -- mine isn't the prettiest PHP, but it does the trick.
This is a play off the filter suggested by Katie, which I ran across in few support forums as well. This goes in your functions.php
:
add_filter( 'getarchives_where', 'customarchives_where' );
add_filter( 'getarchives_join', 'customarchives_join' );
function customarchives_join( $x ) {
global $wpdb;
return $x . " 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)";
}
function customarchives_where( $x ) {
global $wpdb;
$categories = get_terms( 'taxonomy-name', 'orderby=id' );
$includeIds;
$i = 0;
foreach($categories as $category) {
if($i != 0) $includeIds .= ',';
$includeIds .= $category->term_id;
$i++;
}
return $x . " AND $wpdb->term_taxonomy.taxonomy = 'taxonomy-name'
AND $wpdb->term_taxonomy.term_id IN ($includeIds)";
}
In the second function, swap taxonomy-name
for the name of your actual custom taxonomy.
All the IDs of terms in your custom taxonomy are captured in a string; the rest operates the same as the original function -- only that list of categories from your custom taxonomy are included in the wp_get_archives()
list. You can also tweak the code to exclude them as well (first example above).
If you only want one instance of the wp_get_archives()
list to do this, just skip the top two lines of code in your functions.php
that apply the filters. Then, when you use the wp_get_archives()
tag, apply the filters before it, and remove them afterwards:
<?php
add_filter( 'getarchives_where', 'customarchives_where' );
add_filter( 'getarchives_join', 'customarchives_join' );
wp_get_archives();
remove_filter( 'getarchives_where', 'customarchives_where' );
remove_filter( 'getarchives_join', 'customarchives_join' );
?>