I'm listing out all posts of a custom post type on a page. I want to remove one category from the query as I'm using it to categorize posts with gated content and as such don't want them to display.

Here's my query:

$category = get_cat_ID( 'Gated' );
$exclude = '-'.$category;
$args = array(
    'post_type'      => 'resource',
    'posts_per_page' => -1,
    'cat'            => $exclude,

$loop = new WP_Query( $args );

But what ends up being 'cat' => -46 doesn't seem to be doing anything at all, the posts Categorized as "Gated" still display.

From what I've read in the codex etc, I feel like I'm doing this correctly. But apparently I'm not? I've run out of different ways to tweak this. Please help!

(FYI $exclude prints out the right category ID + -, and I have tried manually entering the -46)

  • With the exception of the missing $ in the args variable which I'm assuming is a mistype, your code runs fine on my test site. You may have a pre_get_posts affecting the query elsewhere / not shown here. – Howdy_McGee Jan 26 '17 at 22:57
  • Thanks for confirming this works. And yes, the missing $ was a mistype. – zfors Jan 26 '17 at 23:07

After @Howdy_McGee confirmed the code works I had to look elsewhere. I noticed I had a duplicate post with the same title (that WASN'T categorized as "Gated") that was always displaying. So I didn't notice when the Gated one was disappearing. >.<

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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