I’m currently using the following plugin on my WordPress website to show our up coming events:
https://wordpress.org/plugins/import-eventbrite-events/
I need to write an IF statement that will check the custom post type and then a category of the post type which will then return my custom code.
So far I’ve tried the following code:
if ( is_singular( ‘eventbrite_events’ ) && has_category( ‘network’ ) )
If I remove the category reference it works, but it will show my custom code on all events pages. Whereas I only want it to show the code in a certain category of the custom post type.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
has_category applies only to default post type.
You are working on a CPT so you should use has_term()
if ( is_singular( 'eventbrite_events' ) && has_term( 'network', '{YOUR_CUSTOM_TAXONOMY}' ) )
where {YOUR_CUSTOM_TAXONOMY} is optional and it must be the slug for eventbrite_events taxonomy to which the term ‘network’ is attached to.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0