views:

709

answers:

4

Is there any way to exclude a category from wp_get_archives? I'm trying to show the months in the sidebar, but I want to exclude the posts that are not blog entries.

$catID = get_cat_id('Projects');
$variable = wp_get_archives('type=monthly&show_post_count=1);
echo $variable;
A: 

wp_get_archives() does not have a mechanism to exclude based on category -- it's purely for time-based archives (yearly, monthly, daily, weekly) or "every post" archives: postbypost or post by post ordered by post title.

artlung
A: 

There are different ways to work with category archives: WordPress › Support » Limit archives to category / date archives for category

I use Clean Archives Reloaded WordPress › Clean Archives Reloaded « WordPress Plugins and exclude categories around line 200:

// Get a simple array of all posts
$rawposts = get_posts( 'numberposts=-1&category=-4,-6,-7,-9' );
songdogtech
Any of these work?
songdogtech
A: 

You might want to look in to get_categories and lean towards your own custom solution. While this may cost you a little more time and work; you will indeed get the upshot of having full control over what you're trying to achieve.

hsatterwhite
A: 

Can you use a filter hook on pre_get_posts instead?

I know something like this works for is_author, is_home, and is_feed...

function exclude_stuff($query) { 
if ( $query->is_author) {
$query->set('cat', '-4, -142');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_stuff');

depends on whether you can do it for something like is_archive or is_monthly

You would drop that in a php file with a plugin header:

<?php
/*
 * Plugin Name: exclude some stuff
 * Description: blah
 * Author: blah
 * Plugin URI: blah
 * Version: 0.9
 * =======================================================================
*/
   Put the function here
?>

Then upload it to your Plugins directory and activate it.