WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made a related post sidebar widget and im trying to exclude a category from it i tried 'exclude'=>7932 but that doesnt seem to work, is there another way to do this?

            <?php $category = get_the_category();
            $parent = get_cat_id($category[0]->category_parent);
            $parent = $category[0]->cat_id; ?>
            <ul class="recent-widget-container">
            $categories = get_the_category($post->ID);
            if ($categories) {
            $category_ids = array();
            foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
            'category__in' => $category_ids,
            'post__not_in' => array($post->ID),
            'showposts'=>5, // Number of related posts that will be shown.

            $my_query = new wp_query($args);
            if( $my_query->have_posts() ) {
            while ($my_query->have_posts()) {
            <?php $id = get_the_ID(); ?>

            <?php $image_meta = get_post_meta($id,'image',true); ?>

            <li class="recent-widget-post">
            <div class="recent-widget-img">
            <?php if ( (isset($image_meta)) && ($image_meta != '') ) { 
            }else{  echo $small_placeholder;}   ?>
            <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
            <p><?php get_the_excerpt_limit( 75, '...' ); ?></p>
            <div class="fix"></div>
            $post = $orig_post;
share|improve this question

Use category__not_in => array(7932) instead. http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.