Support

Home Forums Event Espresso Premium Custom Queries

Custom Queries

Posted: February 11, 2015 at 3:11 pm

Viewing 4 reply threads


Peyton Earey

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.


Lorenzo Orlando Caum

  • Support Staff

February 12, 2015 at 6:21 am

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/


Lorenzo


Peyton Earey

February 12, 2015 at 8:24 am

Ok, great. But using your query here:
http://developer.eventespresso.com/docs/ee-model-objects-and-custom-post-types/

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:
Your code

Mine:
Mine


Josh

  • Support Staff

February 13, 2015 at 3:49 pm

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 '

'. $event_obj->name() . '

'; echo '

' . $event_obj->description() . "

"; // get the next upcoming start date from all the available datetimes $datetimes = $event_obj->datetimes_ordered( $show_expired = false, $show_deleted = false, $limit = 1 ); foreach ( $datetimes as $datetime ) { $startdate = $datetime->start_date_and_time(); } echo '

The next upcoming date is ' . date_i18n( 'F j, Y', strtotime( $startdate ) ) . '

'; }

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!


Peyton Earey

February 16, 2015 at 3:02 pm

Great info, thanks!

Viewing 4 reply threads

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.

Event Espresso