Posted: September 26, 2015 at 3:16 pm
|
I currently use the following lines to query upcoming events:
Most events have several datetimes, but I wish to only show events where the first datetime hasn’t passed. The above returns all events with any datetime in the future. I can’t find a listing of the possible criteria. What I’ve tried for example is to add: And I wouldn’t know how to implement Hope someone can help me out with this problem. Thanks! |
Hi there Ruben, Here are some resources to our developer documentation: http://developer.eventespresso.com/docs/using-ee4-model-objects/ http://developer.eventespresso.com/docs/model-querying/ Here is an example of how to get the information that you are looking for: $events = EEM_Event::instance()->get_all( array( array( 'AND' => array( 'Datetime.DTT_order' => 1, 'Datetime.DTT_EVT_end' => array( '>', time() ) ) ), 'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ) ) ); — |
|
|
That code indeed returns the correct events. Thanks! One step remains.. The code I use relies on post objects, such as `EE_Event_List_Query’ returns. Is there a way to convert the array returned by your code into an array of the related post objects? Or perhaps query the required attributes found in this page using EE_Event_List_Query? |
Hi Ruben, You should be able to adapt the above to modify your EE_Event_List_Query() with a function like this: /* only show events where the first datetime hasn’t passed */ function custom_posts_where_sql_for_only_not_expired() { $dttable = EEM_Datetime::instance()->table(); return ' AND ' . $dttable . '.DTT_order = 1 AND ' . $dttable . '.DTT_EVT_end > ' . time() . ' '; } the right before you do the query, you call your function on the posts_where filter like this:
|
|
|
It works like a charm! It doesn’t seem intuitive to me, so I’ll further read into filtering posts using SQL, as I also need to have this working for the events listing shortcode. Thanks a lot for your help! |
Here’s a great resource that will help: https://pippinsplugins.com/look-posts_where-filter/ You can also review this code as well: While it doesn’t filter out events based on the first datetime, it’s similar in the way it uses the posts_where filter to exclude events that have tickets that are no longer for sale. |
|
The support post ‘Query only where the first datetime is on or after today’ 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.