12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Aug 29, 2021

How to Exclude Items Having A Specific Taxonomy Term from a CPT Archive

Sridhar Katakam

This members-only tutorial provides the code to exclude a Custom Post Type's items that belong to a specific taxonomy on that CPT's archive page.

Scenario:

CPT: case_study

Taxonomy: industry
Sample taxonomy terms: Manufacturing, Pharmaceuticals, Chemicals, Food

Requirement: Case Study CPT archive should show all the case study posts except those are assigned to the Manufacturing term.

pre_get_posts to the rescue!

Add the following using a plugin like Code Snippets:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right