Support

Home Forums Event Espresso Premium Documentation/Args for EE_Event_List_Query

Documentation/Args for EE_Event_List_Query

Posted: September 20, 2016 at 3:21 am

Viewing 11 reply threads


deckchairuk

September 20, 2016 at 3:21 am

Hello,

I’m using EE_Event_List_Query to list all upcoming events but would like to add a meta query to the query so only those with a certain custom field value are included in the list.

I can’t find any documentation RE. EE_Event_List_Query and if it can do meta_queries in any way. Could you point me in the right direction for where to find some documentation on this or if you have a better idea for how I can solve this problem, your help would be greatly appreciated.

Thanks, Harry.


Josh

  • Support Staff

September 20, 2016 at 11:13 am

Hi Harry,

The EE_Event_List_Query class is not intended to be used outside of the Event Espresso short code, so that’s why there isn’t documentation on how to add custom fields or anything like that. You can look through its source to see how it works and the arguments it uses:

https://github.com/eventespresso/event-espresso-core/blob/master/shortcodes/espresso_events/EES_Espresso_Events.shortcode.php#L147

Another approach you can take would be write a regular WordPress custom post type query e.g.
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters


deckchairuk

October 4, 2016 at 8:55 am

Hi Josh, thanks for your reply.

I am using the EE_Event_List_Query as on a lot of the support posts I’ve read it’s been suggested to use that to do custom queries. I would use regular ones but I can query on the start date in a regular query as I believe it’s protected meta.

I really need to run a meta_query to remove posts with a certain custom field value, can you see any way of me doing this whilst also ordering by the start date set in event espresso?

Thanks, Harry.


Josh

  • Support Staff

October 4, 2016 at 9:22 am

The start date is actually not part of protected meta. It’s in another database table that you can do a join on. Here’s a link to a code example:

https://gist.github.com/joshfeck/103efd299ce615188e978293a1254eeb


deckchairuk

October 4, 2016 at 9:57 am

Hi Josh,

That’s great, thanks!

Would I be able to set show expired to false too?

Thanks, Harry.


Josh

  • Support Staff

October 4, 2016 at 10:16 am

Show expired is controlled by what you send to the posts_where filter. In the code example on line 21 it’s setting it to only show events where their datetime end is after right now.


deckchairuk

October 5, 2016 at 9:14 am

Hey Josh,

I’ve tried to get the filters in as you mentioned but to no avail, I’m fairly new to using these so I’m really sorry but would you be able to help point me to how I would integrate this?

I’ve build my query that filters the posts with the certain custom meta, I just need to order them by start date and remove any that have expired.

https://gist.github.com/lorenzocaum/9ed2392d7a58d229406cc72289d47a63

Thanks, Harry.


deckchairuk

October 5, 2016 at 9:16 am

Sorry forgot to remove indents! I’ve created a gist instead; https://gist.github.com/deckchairuk/d75b44fdadfed511b9c7542d0b883641

Thanks, again.


Josh

  • Support Staff

October 5, 2016 at 1:42 pm

I’m not seeing anywhere in your code where you’re actually putting a filter on posts_where or any other filter hook for that matter.


deckchairuk

October 6, 2016 at 2:11 am

Hi Josh,

Sorry I must have removed them before sending that over to you, I’ve edited it to show you where I had the filter before.

https://gist.github.com/deckchairuk/d75b44fdadfed511b9c7542d0b883641

Sorry about that.


deckchairuk

October 6, 2016 at 4:46 am

Hey again,

I think I have solved this now. I used pre_get_posts instead of posts_where and it seems to be working.

I updated the gist to show what I did.

Thanks for your assistance.


Josh

  • Support Staff

October 6, 2016 at 10:02 am

Yeah pre_get_posts is an appropriate hook for modifying the query.

Viewing 11 reply threads

The support post ‘Documentation/Args for EE_Event_List_Query’ 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