Support

Home Forums Event Espresso Premium Exclude Event Categories from Upcoming Events Widget

Exclude Event Categories from Upcoming Events Widget

Posted: January 22, 2020 at 1:28 pm

Viewing 7 reply threads


nlctampa

January 22, 2020 at 1:28 pm

Hi,

I’m trying to remove some events from displaying on the upcoming events widget.

add_filter('FHEE__EEW_Upcoming_Events__widget__where', 'filter_invitation_only',10,3);
function filter_invitation_only($where, $category, $show_expired) {
$where['EVT_slug'] = array('NOT LIKE', '%ceo-circle%');
return $where;
}

Currently, this works great to remove the events that match the slug, but ideally, we would remove all events in a category. How do I rewrite that WHERE definition to exclude all events within a category?

Thanks!


Tony

  • Support Staff

January 23, 2020 at 2:20 pm

Hi there,

I highly recommend taking a look at our model documentation, available here:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md

To alter the query to return events not in a specific term, you can use the slug like so:

$where['Term_Taxonomy.Term.slug'] = array( '!=', '{slug}' );

Or the term_id if preferred:

$where['Term_Taxonomy.Term.term_id'] = array( '!=', 20 );

20 being an example ID, you’d use your own.

  • This reply was modified 4 years, 10 months ago by Tony.


nlctampa

January 23, 2020 at 3:30 pm

Thank you for the help!

I did review the documentation, but it’s not clear on how to access taxonomy attributes.

I tried both code examples, but no luck. The events are not being excluded.

add_filter('FHEE__EEW_Upcoming_Events__widget__where', 'filter_invitation_only',10,3);
function filter_invitation_only($where, $category, $show_expired) {
$where['Term_Taxonomy.Term.term_id'] = array( '!=', 335 );
return $where;
}

I also tried:
$where[‘Term_Taxonomy.Term.slug’] = array( ‘!=’, ‘invitation-only’ );

Screenshot showing the category ID: https://drive.google.com/file/d/11PKOADxtantA1MedIT_RUMCxB9-pMSlX/view

Any idea why it’s not excluding events with that category from the query?

Thanks!


Tony

  • Support Staff

January 23, 2020 at 4:07 pm

Hmm, strange.

Do you have a category set on the widget? (Within the widget options, not through code)


nlctampa

January 23, 2020 at 5:07 pm

Nope, it’s set to display all. https://drive.google.com/file/d/14S5Pyl45E6ArGwbh5ekqLUZxnv8-Ny8_/view?usp=drivesdk

Any other way of excluding one taxonomy term?


Tony

  • Support Staff

January 24, 2020 at 6:49 am

Any other way of excluding one taxonomy term?

No.

What happens when you also set the taxonomy?

$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
$where['Term_Taxonomy.Term.term_id'] = array( '!=', 335 );

If that doesn’t work I’ll need to view the widget and an event set on the above term.


nlctampa

January 28, 2020 at 8:29 am

I think that did it!

Thank you!


Tony

  • Support Staff

January 28, 2020 at 8:47 am

Hmm, ok.

I’m glad that’s fixed it, but that means all of your events are in at least 1 category, correct?

If so, is that always the case? (If it is it’s fine as is).

Viewing 7 reply threads

The support post ‘Exclude Event Categories from Upcoming Events Widget’ 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