Show future dates only in CMS section

3 posts by 2 authors in: Forums > CMS Builder
Last Post: 3 hours ago   (RSS)

Is there a way to show only future events in the CMS editor?  I can show them correctly in the output, but can I sort to show only current/future dates in a date DESC order inside the CMS?  Thanks for any help.

celuch

Hi celuch,

There's no built-in way to permanently hide past records from the editor list. That one needs a small custom plugin (or code change).

Try saving this in your /plugins/ folder as futureDatesOnly.php (or something similar):

<?php
/*
Plugin Name: Future Dates Only
Description: Hides past-dated records from a section's editor list, so users only see upcoming records.
Version: 1.00
*/

use Itools\Cmsb\Plugin;

Plugin::on('list_where', function (string $where, string $table): string {
    $forTable  = 'events';
    $dateField = 'event_date';
    if ($table === $forTable) {
        $where = "($where) AND `$dateField` >= CURDATE()";
    }
    return $where;
});

Just change $forTable and $dateField to match your table and field.

Hope that helps, let me know any questions.

Thanks!

Dave Edis - Senior Developer
interactivetools.com