Support

Home Forums Event Espresso Premium Query sorted by start date

Query sorted by start date

Posted: February 28, 2019 at 1:48 pm


Antenna Digital

February 28, 2019 at 1:48 pm

Trying to output the next 3 events on the home page. Using this following query

<?php
// Query Arguments
$atts = array(
'limit' => 3,
'post_status' => 'publish',
'show_expired' => FALSE,
'order_by' => 'start_date',
'sort' => 'ASC',
);

// Query
$query = new EE_Event_List_Query($atts);
?>

But regardless of whether I use ‘sort’ => ‘ASC’ or ‘sort’ => ‘DESC’ the events are coming out in the same sort order.

Tried various snippets from the forum but none worked as expected.
Seems like a simple query….so I suspect it’s something simple I’m missing.


Josh

  • Support Staff

February 28, 2019 at 3:04 pm

Hi,

I believe EE_Event_List_Query has been deprecated so the query probably doesn’t have access to do the joins needed on the datetime table.

What you could do instead is use the built in model system to do the query, it handles the joins for you. Here’s a code snippet that shows an example:
https://gist.github.com/joshfeck/6e33532c37a123bbf532


Antenna Digital

March 1, 2019 at 7:08 am

Thanks Josh
This gets me most of the way there.
I do need to get the start date for the event and have been unable to get that so far. I tried print_r on the $event array but that did not seem to contain the date.

Can you tell me how to get the start date or perhaps point me to a resource that shows how to get elements out of $event when I use the snippet provided?

Thanks


Josh

  • Support Staff

March 1, 2019 at 8:13 am

Hi,

There are a number of template tags you can use for this. Here’s a link to the source for one of them:

https://github.com/eventespresso/event-espresso-core/blob/master/public/template_tags.php#L589

You’ll note the third parameter takes the event ID, which you can get from the $event object. So for example the following will echo out the event’s next upcoming datetime using the date and time format set in WP > Settings:

espresso_next_upcoming_datetime( '', '', $event->ID(), true );

The support post ‘Query sorted by start date’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Josh 2 weeks, 4 days ago ago

Topic Tags

Tagged: ,

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!