Title: Exclude category
Last modified: July 14, 2021

---

# Exclude category

 *  Resolved [clydefrog1](https://wordpress.org/support/users/clydefrog1/)
 * (@clydefrog1)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/exclude-category-73/)
 * On my site, I exclude the category from the whole site this way:
 *     ```
       function exclude_category($query) {
           $query->set('cat', '-2370');
       }
       if(!is_admin()){
         add_action( 'pre_get_posts', 'exclude_category' );
       }
       ```
   
 * but the plugin still displays posts from this category, even if I entered
 *     ```
       'taxonomy' => 'category',
       'term_id' => -2370,
       ```
   
 * Is there a solution?

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

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14659979)
 * Hi [@clydefrog1](https://wordpress.org/support/users/clydefrog1/),
 * Hard to say what’s happening without more info. If I had to guess, if you’re 
   using multiple categories with your posts then WPP won’t exclude a post from 
   the list if it the post also belongs to another category that’s being allowed.
 *  Thread Starter [clydefrog1](https://wordpress.org/support/users/clydefrog1/)
 * (@clydefrog1)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14662517)
 * Hello [@hcabrera](https://wordpress.org/support/users/hcabrera/),
    Post has only
   one category (id = 2370) and if I remove the function “exclude_category” from
   the functions.php then the post is not displayed via the plugin.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14665318)
 * Alright, I’ll do some testing and report back as soon as possible.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14671715)
 * Hi [@clydefrog1](https://wordpress.org/support/users/clydefrog1/),
 * Alright so I tried to reproduce the issue and the category filtering worked as
   expected for me. Using the `pre_get_posts` function in functions.php didn’t make
   any difference at all, WPP was able to filter out posts from the selected category
   just fine.
 * [⌊Category List screenshot⌉⌊Category List screenshot⌉[
 * [⌊Posts list in admin section showing category assignments⌉⌊Posts list in admin
   section showing category assignments⌉[
 * [⌊wpp_get_mostpopular() function screenshot⌉⌊wpp_get_mostpopular() function screenshot⌉[
 * [⌊pre_get_posts code snippet in functions.php file⌉⌊pre_get_posts code snippet
   in functions.php file⌉[
 * [⌊Popular Posts list on the front-end with category exclusion⌉⌊Popular Posts 
   list on the front-end with category exclusion⌉[
    -  This reply was modified 4 years, 10 months ago by [Hector Cabrera](https://wordpress.org/support/users/hcabrera/).
      Reason: Fixed screenshot not loading
 *  Thread Starter [clydefrog1](https://wordpress.org/support/users/clydefrog1/)
 * (@clydefrog1)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14674504)
 * Ok, I tried disabling all other plugins, but it didn’t help. Maybe I can provide
   some other information?
 * [
      [   [
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14675960)
 * If the issue still persists even after deactivating all of the other plugins 
   then the only two things I can think of at the moment are:
    - Page caching: are you using a caching plugin? Or is your hosting service providing
      some sort of page caching mechanism automatically for you? Or are you using
      a CDN based caching service, like Cloudflare for example?
    - There might be an issue with your own code. You can share it here if you want
      me to review it.
 *  -  This reply was modified 4 years, 9 months ago by [Hector Cabrera](https://wordpress.org/support/users/hcabrera/).
      Reason: Reworded for clarity
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14710708)
 * Closing topic due to inactivity.
 * OP if you still need help with this please feel free to leave a comment below.

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

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

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [exclude](https://wordpress.org/support/topic-tag/exclude/)

 * 7 replies
 * 2 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/exclude-category-73/#post-14710708)
 * Status: resolved