Title: Exclude specific posts or category
Last modified: January 19, 2023

---

# Exclude specific posts or category

 *  Resolved [Roger](https://wordpress.org/support/users/erpol53/)
 * (@erpol53)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/exclude-specific-posts-or-category/)
 * Hi,
 * I need to exclude some specific posts from the archive (or a whole category if
   it’s simpler). Is there a way to do this with a filter ?
 * Since you rewrote the code, I can’t make sense of it any more! Sorry.
 * Thanks for your help, and for a great plugin.
 * RP

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Ashley](https://wordpress.org/support/users/nosegraze/)
 * (@nosegraze)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/exclude-specific-posts-or-category/#post-16392226)
 * Hi [@erpol53](https://wordpress.org/support/users/erpol53/) 🙂
 * The easiest way is to use the “expanding_archives_get_posts” filter. This is 
   a filter that runs on the WP_Query args. That means you can apply any changes
   you want there, which are compatible with WP_Query.
 * Here are the docs for WP_Query category filters: [https://developer.wordpress.org/reference/classes/wp_query/#category-parameters](https://developer.wordpress.org/reference/classes/wp_query/#category-parameters)
 * So excluding a category would look like this:
 *     ```wp-block-code
       add_filter('expanding_archives_get_posts', function(array $args) {
            $args['category__not_in'] = [2]; // Replace with ID of your category.
   
            return $args;
        });
       ```
   
 * Change the number “2” to the ID of the category you want to exclude.
 * This code would go in a custom plugin or your theme’s functions.php file.
 *  Thread Starter [Roger](https://wordpress.org/support/users/erpol53/)
 * (@erpol53)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/exclude-specific-posts-or-category/#post-16392700)
 * Hi Ashley 😊,
 * Thanks a lot for the super quick response. Your plugin is really the best and
   more flexible archive one out there, and believe me I’ve looked!
   Unfortunately
   the filter doesn’t seem to work. I tried different variations of the code in 
   functions.php (which has other stuff that works), and I settled on what seems
   the most correct syntax to me:
 *     ```wp-block-code
       add_filter('expanding_archives_get_posts', 'exclude_cat_archive');
   
       function exclude_cat_archive(array $args) {
       	 $args['category__not_in'] = 2; // Replace with ID of your category.
   
       return $args;
       } 
       ```
   
 * Any ideas ? FYI the opposite doesn’t work either, to ONLY display the given category,
   with category__in.
 * But in your examples for displaying just one category, you put 2 filters and 
   some additional code. Am I missing something ?
 * Thanks for your help,
 * Roger
    -  This reply was modified 3 years, 4 months ago by [Roger](https://wordpress.org/support/users/erpol53/).
 *  Plugin Author [Ashley](https://wordpress.org/support/users/nosegraze/)
 * (@nosegraze)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/exclude-specific-posts-or-category/#post-16392951)
 * You’ll want the “2” in brackets like I noted before, because the WP_Query docs
   note it should be an array — not an integer. 🙂
 * I forgot to mention that the results are cached. So that’s why you’re not seeing
   the changes reflected. The cache is stored in transients. You can use a plugin
   like this one to manage transients: [https://wordpress.org/plugins/transients-manager/](https://wordpress.org/plugins/transients-manager/)
   Then you can delete any that start with “expanding_archives”.
 *  Thread Starter [Roger](https://wordpress.org/support/users/erpol53/)
 * (@erpol53)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/exclude-specific-posts-or-category/#post-16393713)
 * Yes, it works! I had started with this syntax, but I thought it wasn’t working
   because of the transient thing – after deleting ‘expanding_archives_months’, 
   it started working.
 * The month is still showing as having the post, but the post itself doesn’t appear–
   I can work with that!
 * Thanks a lot for your reactivity and helpfulness.
 * Roger

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exclude specific posts or category’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/expanding-archives.svg)
 * [Expanding Archives](https://wordpress.org/plugins/expanding-archives/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/expanding-archives/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/expanding-archives/)
 * [Active Topics](https://wordpress.org/support/plugin/expanding-archives/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/expanding-archives/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/expanding-archives/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Roger](https://wordpress.org/support/users/erpol53/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/exclude-specific-posts-or-category/#post-16393713)
 * Status: resolved