Exclude category

There are a few ways you can exclude posts in certain categories from your listings.

By Category ID

By default, the category_id parameter limits results to posts IN these categories. For instance, [display-posts category_id="123"] displays posts in the category with an ID of 123.

You can use negative numbers to exclude categories. If you want posts in all categories EXCEPT 123, use [display-posts category_id="-123"]

By Category Name

For more advanced category filtering – like excluding categories by name – you can use the Taxonomy Query parameters.

[display-posts taxonomy="category" tax_term="featured, news" tax_operator="NOT IN"]

Technically we’re using the category slug, not the name. If your category is named “My Great Category”, the slug is likely my-great-category. Go to Posts > Categories to see a list of all your categories with their names and slugs.

A taxonomy is a way to group things together. WordPress comes with ‘category’ and ‘post_tag’ taxonomies by default, and you can add additional taxonomies with plugins.

A taxonomy term is a name of a grouping inside your taxonomy. These are your individual categories or tags.

The parameters you’ll use are:

  • taxonomy = the name of the taxonomy (ex: category, post_tag, or a custom taxonomy)
  • tax_term = one or multiple category/tag slugs, separated by comma
  • tax_operator = NOT IN for excluding these categories. Other options include IN and AND

Multiple taxonomy queries

You can also chain together multiple taxonomy queries, like “Show posts in these two categories and exclude posts in this specific category.

[display-posts taxonomy="category" tax_term="events, news" tax_operator="IN" taxonomy_2="category" tax_2_term="hidden-posts" tax_2_operator="NOT IN"]

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.