Posted: September 9, 2023 at 2:25 pm
Hi, I am trying to understand how to call an Event Category ID or Event Category Name into an if statement as part of a WP custom template. Normally for a non-custom post type, I might do something like this to change the background of a banner based on category. How can I do this within this custom event taxonomy? I am sure it’s a simple answer that I just didn’t find. Thanks,
</div> |
|
My preference would be to do this by Event Category ID. Basically: If Event Cat ID is 91, do this… if Event Cat ID is 92, do that |
|
Hi Jon, So, within WordPress you have ‘Taxonomies’ which are basically just a way to organize content. You have default taxonomies built into WordPress and those are ‘Categories’, ‘Tags’ and ‘Post Formats’ and when you set a category on a standard WordPress post it will be using the ‘Category’ taxonomy, each different category you add to that is a ‘term’ within that taxonomy. So a post ‘category’, is a term within the category taxonomy. An EE event category is a term within the espresso_event_categories custom taxonomy. Your opening posts suggest you know most of the above, so why am I telling you this? Because in_category() just checks for terms within the default ‘Category’ taxonomy. Looking through in_category() it just uses has_category() (we are almost there I promise!), which is basically just this:
So that’s checking for ‘$categrory So to use your example above And yes, you can pass the term_id in place of the name there. —- Side note, there always multiple ways to do things and if you have the above, I assume you have the EE_Event object (If you have the WP_Post object for an EE event you should also have the EE_Event object assigned to that or again there’s multiple ways of getting that ;)) If you want to look at another way of doing this you could use:
(Assuming the EE_Event object is within |
|
The support post ‘Working with Event Espresso Event ID’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.