Posted: November 18, 2015 at 2:45 pm
|
I have created a custom post type called ‘Course’. Using the ACF plugin, I can associate a ‘Course’ with an EE Event. On each ‘Course’ page I would like to display all upcoming events associated with the ‘Course’ being displayed. This cannot be accomplished using shortcode. How can I use EE models, classes or template tags to build a query to return the results I need? |
Event Espresso events are also custom post types, stored in the WP posts table, so I don’t think you’ll need to use EE models, classes, or template tags to build the query. If you’re using ACF’s relationship fields, you can do a query like the one in their documentation: |
|
|
In my case the relationship is backward from this example. The custom field is on the EE event, but I’m viewing my ‘Course’ custom post type when I run the query. I’ve got something that works, but I want to refine it so I’m only looking for upcoming events in the query, rather than filtering the results for upcoming events afterwards. Here’s the code I have now:
How can I rewrite this so upcoming events are filtered in the get_posts() arguments rather that when I’m looping through the results? |
I’d rewrite it like so:
This will get all upcoming events, ordering them by when the event’s datetime actually happens, not just when the event was published (I’m assuming that’s what you’re going to want. I could be wrong) |
|
|
This is perfect. How do I modify this query to return the venue information as well? |
Note that in the database, it’s actually possible to have multiple venues for an event.
Checkout the Venue class: https://github.com/eventespresso/event-espresso-core/blob/master/core/db_classes/EE_Venue.class.php |
|
The support post ‘Querying events on ACF custom field’ 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.