If you use custom post types, you’ll often have the need to do something if the current post has a specific term from a custom taxonomy.
You can accomplish this using the following:
All you need to do here is change the TERM to the name of the category within the custom taxonomy (exactly what you’ve called it, include spaces etc) and then add the name of the custom taxonomy.
The above snippet will then only echo out the code when the term is present in the current post.
When might this be handy?
This little snippet is best used if:
- You want to use a custom post type template to be used with a custom taxonomy and have certain content displayed depending on the current custom term (within your custom taxonomy)
- You can do all kind of things with this – our requirement was to show a specific WordPress menu when a particular term was used so we could display a menu of related content
If you are planning to have lots of terms (categories) we would suggest using the built-in WordPress categories, as these are a lot easier to work with.
Don’t forget that we offer WordPress support for any issue you have with WordPress. If you need help, just get in touch.