Title: Excluding multiple categories using $exclude[] tree
Last modified: August 20, 2016

---

# Excluding multiple categories using $exclude[] tree

 *  Resolved [muhammadwaqas](https://wordpress.org/support/users/muhammadwaqas/)
 * (@muhammadwaqas)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/excluding-multiple-categories-using-exclude-tree/)
 * hello, I’m having a little problem. I’ve search the whole internet
 * here is my code
 *     ```
       <?php
       		$exclude = get_option( 'sticky_posts' );
       		$exclude[] = $category[0]->cat_ID;
       		$loop = new WP_Query(
       			array(
       				'category__not_in' => $exclude,
       				) );
       		$m = 0;
       		while ( $loop->have_posts() ) : $loop->the_post(); $m++;
       		?>
       ```
   
 * Im using this code to get recent posts in single.php currently I’m eliminating
   the recent posts of from “Current Category” being watch in single.php
 * but I want to exclude another category. can anyone help me too exclude multiple
   categories.

Viewing 1 replies (of 1 total)

 *  Thread Starter [muhammadwaqas](https://wordpress.org/support/users/muhammadwaqas/)
 * (@muhammadwaqas)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/excluding-multiple-categories-using-exclude-tree/#post-3203972)
 * just solved my problem without any help, the full working code is
 *     ```
       <?php $category = get_the_category(); ?>
           <?php
           $exclude = get_option( 'sticky_posts' );
           $exclude[] = $category[0]->cat_ID;
           $loop = new WP_Query(
               array(
                   'category__not_in' => $exclude,
                   'cat'=> -36,
                   ) );
           $m = 0;
           while ( $loop->have_posts() ) : $loop->the_post(); $m++;
           ?>
           my content goes here
           <?php endwhile; ?>
           <?php wp_reset_query(); ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Excluding multiple categories using $exclude[] tree’ is closed to new
replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [muhammadwaqas](https://wordpress.org/support/users/muhammadwaqas/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/excluding-multiple-categories-using-exclude-tree/#post-3203972)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
