Include/Exclude Category from WordPress wp_get_archives()

For some reason, WordPress’ “wp_get_archives()” function does not allow us to include or exclude categories by default.  This is weird, because many other WordPress hooks include this basic functionality.

Thankfully, after struggling for a bit today, I discovered this plugin that solves the issue.  It hooks directly into the WordPress core, so customizing is a breeze!  Simply add “cat=5” (with the number “5” being the id of the category you want to include) to the “get_archives” parameters in your template file!  It’ll look like this: <?php wp_get_archives(‘cat=5’); ?>

Pretty cool, eh?

16 Comments

  1. Danilo on September 17, 2009 at 3:31 am

    thanks a lot!!!!!



    • Toby on September 18, 2009 at 12:44 pm

      No problemo, Danilo! 🙂



  2. Courtney on September 21, 2009 at 6:48 pm

    This is definitely what I was looking for — but it doesn’t seem to work with permalinks.



  3. Toby on September 21, 2009 at 8:59 pm

    @Courtney – What do you mean? Permalinks to blog posts?



  4. Courtney on September 21, 2009 at 10:38 pm

    Hmm, maybe I described that wrong.

    But the real issue is that, while it does filter down the archives list correctly it doesn’t display the contents for a particular month in that list.

    The plugin creates this link for September 08 — http://myurl.com/2009/09/?cat=4 — but if I click on it it displays as http://myurl.com/category/cats/ (“cats” being category with ID of 4). And it displays all entries for that category, not just September 2008.

    I guess what I’d really like is if it did something like:

    http://myurl.com/2009/09/category/cats/.



  5. Courtney on September 21, 2009 at 10:40 pm

    P.S. Shoot, I shouldn’t have used “cats” as my arbitrary category name (“cats” and “category” might be confusing)… Insert “dogs” or whatever category name makes the most sense to understand the scenario.



  6. Phil on January 8, 2010 at 3:56 pm

    Hi Courtney, wondering if you figured out the permalinks issue with this plugin. I’ve been having the same problem I think.



  7. Toby on January 13, 2010 at 10:30 pm

    @Courtney – I see what you are talking about now, but unfortunately, I don’t know how to solve the problem. Perhaps you can find some help on the WordPress.org forums.



  8. Alex on April 20, 2010 at 11:35 am

    Not too sure if there has been a recent update to the plugin, but to make it work with permalinks, just go to the plugin settings page (Settings > Kwebble) and click on “Disable canonical URLs.” Then update. Works fine now for me with neat url permalinks.

    You might already know about this, but thought I’d comment about it just in case.



  9. Tim on April 26, 2010 at 5:16 am

    It doesn’t work.
    If I click on the month, the actual page reloads and it doesn’t goes to the archive.php to list the posts.



  10. Balu on August 16, 2010 at 12:14 am

    Thanks a lot …………………………….



  11. Mind on August 30, 2010 at 2:59 pm

    Great. Thanks



  12. Yub on March 5, 2011 at 12:43 pm

    Does this plug-in work with thesis theme? I tried but not working.

    Here is my code:

    function posts_nav() {
    echo ‘Blog‘;
    wp_get_archives(‘cat=5’);
    echo ”;
    }
    add_action(‘thesis_hook_last_nav_item’,’posts_nav’);

    ?>



  13. toby on March 17, 2011 at 2:05 pm

    @Yub – I have not tried this in the Thesis theme.



  14. Grant on May 15, 2011 at 9:28 pm

    Could this also work if you passed an author ID through the wp_get_archives?

    Thanks



  15. toby on May 17, 2011 at 12:05 am

    @Grant – I don’t know. Please give it a try and let me know!



RSS From Toby’s Blog

  • How Digital Ocean Cost Us Thousands of Dollars in a Single Day
    Here’s the rub for me: My belief is that bad stuff happens, and you need to own it. Digital Ocean definitely did not own it in this case. I wonder how the original founders of Digital Ocean would have reacted had they been in charge… For example, wouldn’t it be nice if an actual human… […]
  • Where uncertainty exists, don’t order specific.
    4 Idiot Case Studies with 2 simple age-old business lessons. The post Where uncertainty exists, don’t order specific. appeared first on Toby Cryns, WordPress Trainer in Minneapolis, MN.
  • “Now THAT was a good meeting!”
    A single effective meeting can change the course of history for a company. Imagine if you could lead effective meetings EVERY DAY! You can, but it takes curiosity & practice. This article is a good place to start your journey to a more effective you. The post “Now THAT was a good meeting!” appeared first […]

More posts from themightymo.com

How to merge multiple csv files via command line

How to merge multiple .csv files via command line

By The Mighty Mo! Design Co. | May 17, 2023

Today I downloaded 29 csv files with tax information. I could import those files 1 at a time into WooCommerce, but wouldn’t it be nice if I could merge them first and then only import a single file? The unix command is simple – just navigate to the folder with all the csv files and…

WordPress Security Services

15 Best WordPress Support and Maintenance Services for 2023: Ensuring Your Website Stays in Top Shape

By The Mighty Mo! Design Co. | April 27, 2023

Small business owners and non-profit leaders know that keeping your website secure, fast, and fully-functional is critical to success.  Here’s the unspoken truth: You can either learn how to do all that tech maintenance and development stuff yourself, or hire someone else to do it. But let’s face it, doing it yourself isn’t always the…

how to set up Cloudflare whitelist for ip

How to Whitelist SEM Rush IPs in Cloudflare

By The Mighty Mo! Design Co. | April 24, 2023

Alright, I’m going to show you how to whitelist a set of IPs on CloudFlare. In our case we use SEMrush and we want to make sure the SEMrush has full access to our sites.

RSS From Toby’s Blog

  • How Digital Ocean Cost Us Thousands of Dollars in a Single Day
    Here’s the rub for me: My belief is that bad stuff happens, and you need to own it. Digital Ocean definitely did not own it in this case. I wonder how the original founders of Digital Ocean would have reacted had they been in charge… For example, wouldn’t it be nice if an actual human… […]
  • Where uncertainty exists, don’t order specific.
    4 Idiot Case Studies with 2 simple age-old business lessons. The post Where uncertainty exists, don’t order specific. appeared first on Toby Cryns, WordPress Trainer in Minneapolis, MN.
  • “Now THAT was a good meeting!”
    A single effective meeting can change the course of history for a company. Imagine if you could lead effective meetings EVERY DAY! You can, but it takes curiosity & practice. This article is a good place to start your journey to a more effective you. The post “Now THAT was a good meeting!” appeared first […]