I'm trying to figure out a simple way to exclude a particular category from a wp_query on my homepage. this particular code is already excluding a post_type (videos) from displaying, and I'm not exactly sure how to implement code for excluding a category as well. Here's the current code:

<div data-st="st-six">
                <div class="feed-heading"><h4>News &amp; Updates</h4><a class="all" href="news/">Visit the News Page</a>

                <?php $main_query = new WP_Query( array(
                         'tax_query' => array(
                                'taxonomy' => 'post_format',
                                'field' => 'slug',
                                'terms' => array(
                                'operator' => 'NOT IN'
                    if ( $main_query->have_posts() ): ?>
                    <?php while ( $main_query->have_posts() ) : $main_query->the_post(); ?>
                        <div class="card">
                            <div class="meta"><?php the_time('F j, Y'); ?></div>
                            <h5 class="gamma"><a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a></h5>
                    <?php endwhile; ?>
                <?php endif; wp_reset_postdata(); ?>

The category I want to exclude is "magazine" (slug name) with tag_ID = 44. any suggestions?

1 Answer 1


You can use simply category__not_in parameter to exclude one or several categories from your result. The sample is like this:

$query = new WP_Query( array( 'category__not_in' => array( 2, 6 ) ) );

To see list of available parameters and complete example, see documentation of WP_Query in developer.wordpress.org

I hope you can use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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