I have two categories on a site - news which contains news posts and blog - which contains blog posts. Each page has a wp_get_archives in the sidebar. I'd like to limit the archive listing by category but after looking at the codex this does not seem possible. http://codex.wordpress.org/Function_Reference/wp_get_archives

<?php wp_get_archives('type=monthly&limit=12'); ?>

That code lists the archives for all the posts, but I want to list archives for just that category. Am I using the wrong function? Or is this not possible?


4 Answers 4


Basically this is possible, but somewhat messy. This function relies on direct SQL query to database, which you can change via getarchives_where and getarchives_join filters.

  • but just for one category... what about if I want to separate the archive in three completely archives. One for blog, one for news and one for exhibitions. I have been able to take part of the URL so I fixed the next label. The problem is that the links of the archive widget always take me to the general archive with links like mysite.com/2012/12 instead of mysite.com/news/2012/12
    – toto_tico
    Commented Jun 26, 2013 at 4:47
  • @toto_tico please ask new question about your issue :)
    – Rarst
    Commented Jun 26, 2013 at 9:33
  • I did here. I finally found an answer that is sort of working. At least, I know I can tweak what is missing.
    – toto_tico
    Commented Jun 26, 2013 at 10:03

I just installed this plugin and it seems to work fine.



I use this code on my site to pull from a specific category (this is in the sidebar - shows just my 'blog' posts and not my 'portfolio' posts):

global $post;
$myposts = get_posts('numberposts=10&category=3&order=DESC');
foreach($myposts as $post) :
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
  • You could expand this and make it show only the posts for the category you're currently on by getting the category slug or ID from the post and passing into a variable. Then use the variable in your query for posts in the sidebar. Look at the $post global for taxonomy stuff or use get_term_by() to pull the whole term object then grab the slug or ID out of it with something like $var = $taxObject->slug; I'd put it in a counter so it only runs on the first post on the page. Commented Feb 7, 2011 at 15:35
  • Hmmm I'm not trying to display posts, I'm trying to display monthly archives like this nikibrown.com/uploads/a0fba9b8d23d24fdfcf76fb5d9eaaab7.png
    – nikibrown
    Commented Feb 7, 2011 at 17:11

i am not sure if this workaround will do : if instead of the archive you use RSS and specify for the RSS the number of post titles to be shown.

it is easy to get the RSS of the category - easy to specify nbre of posts.

no ? would it work ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.