Title: Hide Child Category Posts
Last modified: August 20, 2016

---

# Hide Child Category Posts

 *  [mystifier](https://wordpress.org/support/users/mystifier/)
 * (@mystifier)
 * [15 years ago](https://wordpress.org/support/topic/hide-child-category-posts/)
 * For many years, I have used a plug-in to hide child category posts but after 
   a recent upgrade to 3.1.2, this has stopped working and I have not been able 
   to find a replacement that works.
 * Can anyone advice how to achieve this?
 * **I only want posts for the current category to show.**
 * `while (have_posts()) : the_post(); if(in_category($cat)) {`
 * has been suggested but I don’t have $cat and can’t work out how to set it to 
   current_category.

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

 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [15 years ago](https://wordpress.org/support/topic/hide-child-category-posts/#post-2090769)
 * Not sure but try getting the first category from the post.
 *     ```
       while (have_posts()) : the_post();
       $category = get_the_category();
       if( $category ) {
          $catid = $category->cat_ID;
       }
       ```
   
 * Or maybe:
 *     ```
       while (have_posts()) : the_post();
       if( is_category() ) {
          $category = get_the_category();
          $catid = $category->cat_ID;
       }
       ```
   
 * HTH
 * David
 *  Thread Starter [mystifier](https://wordpress.org/support/users/mystifier/)
 * (@mystifier)
 * [15 years ago](https://wordpress.org/support/topic/hide-child-category-posts/#post-2090776)
 * No joy… I think get_the_category() may need Post_ID as a parameter.
 * This is pretty crippling now so I may have to wind back to an early version where
   plug-ins work and stay there.
 * (Admin suffers in the same way. With several layers of sub-category, filter posts
   by category now returns many tens of pages because it includes every post from
   every child category – this was a dumb idea!).
 *  Thread Starter [mystifier](https://wordpress.org/support/users/mystifier/)
 * (@mystifier)
 * [15 years ago](https://wordpress.org/support/topic/hide-child-category-posts/#post-2090782)
 * The original plug-in, which has served fantastically for years, was very simply:
 *     ```
       <?php
       function kinderlose_where($where) {
         if ( is_category() ) {
           global $wp_query;
           $where = preg_replace('/.term_id IN \(\'(.*)\'\)/', '.term_id IN (\'' . $wp_query->query_vars['cat'] . '\')', $where);
         }
         return $where;
       }
   
       add_filter('posts_where', 'kinderlose_where');
       ?>
       ```
   
 * Is there an obvious reason why this no longer works?
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [15 years ago](https://wordpress.org/support/topic/hide-child-category-posts/#post-2090814)
 * > No joy… I think get_the_category() may need Post_ID as a parameter
 * It gets the first category of the current post unless you pass an ID in, as you
   are in the loop if there is a category it should return it?
 * Missed the [0]
    `$category[0]->cat_ID`
 * David

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

The topic ‘Hide Child Category Posts’ is closed to new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/hide-child-category-posts/#post-2090814)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
