Posted: February 11, 2015 at 3:11 pm
How would one query things like Event Date or Event Description using a WordPress loop or a foreach loop on the CPT, “espresso_events”? Don’t see many code examples beyond displaying the title. |
|
Hi Peyton, here is some documentation on that: http://developer.eventespresso.com/docs/using-ee4-model-objects/ http://developer.eventespresso.com/docs/model-querying/ http://developer.eventespresso.com/docs/ee-model-objects-and-custom-post-types/ — |
|
Ok, great. But using your query here: I’m not returning the same info in the Post Object? I need to access “DTT_EVT_start”, but I don’t see that returned in my query. Couple screen shots using the same example code: Yours: Mine: |
|
Hi Peyton, Here are a few examples and tips on how to query event post types. One thing to keep in mind is there is more than one way to do this: 1) In the tutorial you linked to, it’s using the built in objects and methods. Here’s an example that includes getting the date and description that uses that idea: $posts = get_posts( array( 'post_type'=>'espresso_events','suppress_filters'=>false,'posts_per_page'=>3 ) ); foreach($posts as $post){ $event_obj = $post->EE_Event; echo ' 2) Note that in the above example, it’s getting *the next upcoming datetime*. Some events have more than one datetime, so that might be important. If it’s not important, you can use the espresso_event_date() template tag. 3) If you load in one of the event view helpers, you can use template tags instead of using the methods or direct query to get extra info like the event date, number of tickets available, etc. 4) You can also run a query with EE_Event_List_Query. Hope that helps! |
|
Great info, thanks! |
|
The support post ‘Custom Queries’ 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.