I haven’t found any solution for that…
That’s not possible ?
Is this for monthly archives?
see: http://wordpress.org/support/topic/remove-cetain-post-categories-from-blog-sidebar-archive-list
Try it with this in your theme’s functions.php:
define("INCLUDED_CATEGORIES", '25,55,57');
add_filter( 'getarchives_join' , 'getarchives_join_filter');
function getarchives_join_filter( $join ) {
global $wpdb;
return $join . " INNER JOIN {$wpdb->term_relationships} tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
}
add_filter( 'getarchives_where' , 'getarchives_where_filter');
function getarchives_where_filter( $where ) {
global $wpdb;
$include = INCLUDED_CATEGORIES; // category ids to include
return $where . " AND tt.taxonomy = 'category' AND tt.term_id IN ($include)";
}
// exclude categories on monthly archive pages
function my_post_queries( $query ) {
// do not alter the query on wp-admin pages and only alter it if it's the main query
if (!is_admin() && $query->is_main_query()){
// alter the query for monthly archive pages
if(is_archive() && is_month()){
$query->set('category__in', array(INCLUDED_CATEGORIES));
}
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
Change the category id’s in define("INCLUDED_CATEGORIES", '25,55,57');
to the IDs you want to include.
With this in your functions.php wp_get_archives() will be filtered by the included categories.
http://codex.wordpress.org/Function_Reference/wp_get_archives
Thanks for your help keesiemeijer
Unfortunately it works incompletely:
The months archives are well filtered
– if a month has only posts from excluded categories, it will not be displayed in the archive months list. Right it works
– if a month has posts from both included and excluded categories, if the month is displayed : OK that’s normal
But in the last case, if we click on the month link, then all the posts from this month are displayed…
I haven’t seen any fix for that…
Does your theme’s archive.php query the loop?
Can you paste and submit the full code of archive.php of your theme into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using a pastebin.
Thank you for your answer
I don’t have an archive.php file in my theme.
I saw that the archives list (annual, month, week) was ruled by index.php.
Here is the code fron paste bin.com :
http://pastebin.com/ZckNQjuG
I have no idea if it queries the loop…
Not sure why it’s not working but try changing this:
$query->set('category__in', array(INCLUDED_CATEGORIES));
to this:
$include = array_map('trim', explode(',', (string) INCLUDED_CATEGORIES));
$query->set('category__in', $include);
keesiemeijer, I apologize
The first code you gave to me was OK
I don’t know what confusion I made when I tested it, but it works perfectly.
Thanks a lot and sorry again.
Paul
No problem. I’m glad you got it resolved 🙂