Remove a Category from wp_get_archives list
Sometimes you’ll want to generate an archive list in your WordPress blog to display month-by-month viewing for your visitors. I wanted to do exactly that, however, I had a category which was wasn’t related to my blog posts, in fact, I didn’t want these post showing at all in my archive.
The solution, remove a category from the results by adding this to your functions.php file and changing the category ID number (on line 8) to suit your needs
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;
$exclude = '1'; // category id to exclude
return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id NOT IN ($exclude)";
}
Powered by Facebook Comments