Support

Home Forums Event Espresso Premium Exclude specific category from event listings

Exclude specific category from event listings

Posted: January 20, 2020 at 9:27 am

Viewing 4 reply threads


deon@dieselbrook.co.za

January 20, 2020 at 9:27 am

Hi, what is the proper way (if any) to exclude a specific category from the event archive page, I need to exclude the category with the id of 107 from the overall page. I’ve hidden it with css up until now, but now there is a case of the first few events being in that specific category, so the page shows up blank. as seen on http://www.pia.org.za/events/. I am on EE4.


Tony

  • Support Staff

January 20, 2020 at 9:46 am

Hi there,

You can use a function like this one:

https://gist.github.com/joshfeck/b293aeae61bd3f13dd21

You’ll need to make a couple of changes for the event archive though.

If you only want this to change the EE archive output you change Line 7 and use is_archive( 'espresso_events' ) in place of is_page()

On Line 20 – 21 you set the term slug and tell the query you are passing the slug, you could change that to

'terms' => '107',
'field' => 'id',

To work with the ID as requested.

You can add that to a custom functions plugin on your site, we have some documentation on creating one here:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

Is that what you are looking for?


deon@dieselbrook.co.za

January 20, 2020 at 10:01 am

This works perfectly thank you. However, there the category that I excluded is shown on another page on the site (http://www.pia.org.za/event-category/online-events/) so now, if I go to this page, the events there are obviously excluded due to the pre_get_posts filter. I’ve tried to circumvent this by adding another && clause that reads !is_category(107), but this doesn’t work, how do I then show the categories posts on this page?


deon@dieselbrook.co.za

January 20, 2020 at 10:08 am

Nevermind, I forgot that event espresso is a custom taxonomy. just swapped this with is_tax, so all sorted now. Thank you for your quick response on this!


Tony

  • Support Staff

January 20, 2020 at 6:42 pm

You’re most welcome, I’m glad you found the problem.

Just to clarify for future readers is_category() only works with the WP default taxonomy of categories, as EE uses a custom taxonomy you need to use is_tax() as mentioned.

https://developer.wordpress.org/reference/functions/is_tax/

Viewing 4 reply threads

The support post ‘Exclude specific category from event listings’ 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.

Event Espresso