Hi everyone,
I am working on a custom snippet for my MODX site; and I am running into an issue where the snippet isn’t returning the expected results. What I’m trying to achieve:
Display a list of upcoming events from a custom database table on a specific page.
Snippet Code:
// Custom snippet to fetch and display upcoming events
$output = ‘’;
$query = $modx->newQuery(‘modxEvents’);
$query->where(array(
‘event_date:>’ => time()
));
$query->sortby(‘event_date’, ‘ASC’);
$events = $modx->getCollection(‘modxEvents’, $query);
if ($events) {
foreach ($events as $event) {
$output .= ‘
’ . $event->get(‘event_name’) . ’ on ’ . date(‘F j, Y’, $event->get(‘event_date’)) . ‘
’;}
} else {
$output .= ‘
No upcoming events found.
’;}
return $output;
The snippet should display a list of upcoming events sorted by date.
The snippet only returns “No upcoming events found,” even though there are events in the database with future dates.
No error messages are displayed, and the MODX error log does not show any related errors.
I have checked my database table and confirmed that there are events with future dates. I have also verified that the table is correctly set up and contains the necessary fields.
I have referred guide for help with developing custom snippets in MODX splunk documentation guide but still need help.
Has anyone else faced a similar issue / can spot something I might have overlooked?
Any help or pointers would be greatly appreciated!
Thanks in advance!