Exclude multiple terms from WP_Term_Query by term name

exclude terms from WP_Term_Query

If your website is built with WordPress and you have multiple terms in your “post or custom post type” taxonomy like category or custom_taxonomy. Sometimes we don’t want to display the multiple terms on the website.

In this scenario, We have an option to exclude the terms from WP_Term_Query by term name.

Exclude multiple terms from WP_Term_Query

Let’s understand with one example:

Suppose I have a custom post type with the name “Events” and a custom taxonomy “Event Type” for Events. Please refer to the image

Exclude multiple terms from WP_Term_Query

If you don’t know how to create a custom taxonomy for custom post type then read below suggested article.

Suggested Read: Complete Steps to Create Custom Taxonomy in WordPress

Now let’s add multiple terms for Event Type like “Past” and “Upcoming”.

exclude term from get_terms

Now, Let’s suppose we have an event under both event types but we don’t want to display the “Past” event type on a single event page.

In this case, we need to exclude the term “Past” from the WP_Term_Query and display only the term “Upcoming”.

Are you want to get implementation help, or modify or extend the functionality of this script?

A Tutorialswebsite Expert can do it for you.

Let’s do it using below code snippets:

Exclude term from WP_Term_Query by term name

Get term orderby term name

if you have multiple terms and you want to display order by term name as ascending.

Thanks for reading 🙏  I hope you found this tutorial helpful for your project.  If you did, please consider sharing this post on social media. You can also extend the functionality as per your requirement. Keep learning!.

Are you want to get implementation help, or modify or extend the functionality of this script? submit your paid request

Related posts