Support

Home Forums WP User Integration Filter events in [ESPRESSO_MY_EVENTS]

Filter events in [ESPRESSO_MY_EVENTS]

Posted: September 30, 2021 at 7:17 am

Viewing 3 reply threads


musashi

September 30, 2021 at 7:17 am

Hi.
Currently I’m using EE4 and WP User Integration in my clients’ site.
I want to display the events with ‘seminar’ category only, but I don’t know how.
I copied content-espresso_my_events-event_section.template.php in my child theme, and trying to filter $event with the category, but I’m not sure how to do it.

Can you please help me with this problem?
Waiting for your support.
Thank you.


Tony

  • Support Staff

October 1, 2021 at 4:52 am

Hi there,

We have a filter on the query used to pull the objects in for the My Events section so rather than doing the above (which is after the add-on has pulled the events) I recommend using the FHEE__Espresso_My_Events__getTemplateObjects__query_args filter for this.

You can see an example of that filter in use here:

https://gist.github.com/Pebblo/334ba1f465a367fe9fd14749b9c8dede

To only use events from a specific category, you’ll need something like:

$query_args[0]['Term_Taxonomy.term_id'] = 999;

Where 999 is the ID of your ‘seminar’ category and you would use that in place of line 20 of that snippet.

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/


musashi

October 1, 2021 at 7:56 am

Tony

Thanks for your support!
It really helped much to me, but can you help me one step more?

Can you show 2 or more categories separately with [ESPRESSO_MY_EVENTS]?
If an attendee purchased events in ‘seminar’ category and ‘event’ category, I would like to show them separately in their my page.
Like this.

<Seminar>
detail of event in ‘seminar’ category
detail of event in ‘seminar’ category

<Event>
detail of event in ‘event’ category
detail of event in ‘event’ category

I really appreciate your support.
Thank you.


Tony

  • Support Staff

October 4, 2021 at 4:14 am

We don’t have an option to do that within the add-on and if that’s what you are trying to achieve then the above snippet I gave you for your original question won’t work as it limits the events returned from the query to a specific category.

You’ll need to look into how loop-espresso_my_events-event_section.template.php loops over each event (in an array called $objects) and outputs each individual event using the content-espresso_my_events-event_section.template.php template. To do the above you’ll need to either filter the $objects array so you can organize the events into 2 separate categories and loop over each for each section or use the main query for one set of events and then a custom query for another to do something similar.

This isn’t something I can walk you through but if you are comfortable with PHP you can take a look at our model system here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

Which makes pulling in various EE data relatively simple.

Viewing 3 reply threads

The support post ‘Filter events in [ESPRESSO_MY_EVENTS]’ 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