Support

Home Forums Event Espresso Premium EEM_Event::instance() query on DTT_EVT_start.

EEM_Event::instance() query on DTT_EVT_start.

Posted: May 21, 2024 at 8:00 pm

Viewing 3 reply threads


tneumann

May 21, 2024 at 8:00 pm

I’m trying to pass a date to the query below, and it doesn’t recognize the date when I try anything other than the current day. For example, the date below will return everything instead of the events starting from 12-31. Is there something I’m missing when formatting these queries?

Thank you.

function run_new_event_list_query($eventYear) {

$where = array(
‘Datetime.DTT_EVT_start’ => array( ‘>=’, ‘2024-12-31 23:59:59’ ),
);
$events = EEM_Event::instance()->get_all( array(
$where,
‘order_by’ => ‘Datetime.DTT_EVT_start’,
‘order’ => ‘ASC’,
));


Tony

  • Support Staff

May 22, 2024 at 5:24 am

Hi there,

Take a look at the docs here:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md#querying-datetime-fields

When passing a value for Datetime fields you can use either a DBSafeDatetime object, a Unix timestamp or a string in the sites current WP date/time format (which I assume you are example above is not).

Something like this should work:


$where = array(
	'Datetime.DTT_EVT_start' => array('>=', new \EventEspresso\core\domain\entities\DbSafeDateTime('2024-12-31 23:59:59')),
);
$events = EEM_Event::instance()->get_all( array(
	$where,
	'order_by' => 'Datetime.DTT_EVT_start',
	'order' => 'ASC',
));

Or, you can use:


$DTT_EVT_start = EEM_Datetime::instance()->convert_datetime_for_query(
    'DTT_EVT_start',
    '2024-12-31 23:59:59',
    'Y-m-d H:i:s',
    'UTC'
);

$where = array(
	'Datetime.DTT_EVT_start' => array('>=', $DTT_EVT_start ),
);
$events = EEM_Event::instance()->get_all( array(
	$where,
	'order_by' => 'Datetime.DTT_EVT_start',
	'order' => 'ASC',
));

The latter just creates a DBSateDateTime for you with the values passed.


tneumann

May 22, 2024 at 6:43 am

Got it, thanks. We were trying to pass the dates as they were being returned by the current time function on this example: https://eventespresso.com/topic/build-an-events-loop-query-in-bricks-builder/

We see now how that won’t work. Ultimately, we now have a pretty slick query function that works with the Bricks Builder loop feature, passing parameters for filtering. We’ll be putting together a post about the implementation soon!


Tony

  • Support Staff

May 22, 2024 at 11:38 am

Ohhh! Nice!

We were trying to pass the dates as they were being returned by the current time function on this example: https://eventespresso.com/topic/build-an-events-loop-query-in-bricks-builder/

Hmmm… I’m going to do some digging into this.

Ultimately, we now have a pretty slick query function that works with the Bricks Builder loop feature, passing parameters for filtering. We’ll be putting together a post about the implementation soon!

Please do let us know when you publish, I’m always happy to have a read of other implementations and see what people come up with 🙂

Viewing 3 reply threads

The support post ‘EEM_Event::instance() query on DTT_EVT_start.’ 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