SimpleSearch - Custom Hook to filter out older events by date

No.


You could do something like this:

[[!pdoResources?
    ...
    &includeTVs=`event-date`
    &where=`[[!getWhere]]`
]]

Snippet getWhere:

<?php
$where = [];
//read search parameter
$search_string = $_GET['search'] ?? ''; 

//do some sanitizing
$search_string = $modx->sanitizeString($search_string);
$search_string = strip_tags($search_string);
$search_string = trim($search_string);

if (mb_strlen($search_string) > 2){ //check min search length
    //filter by search term
    $where[] = ["pagetitle:LIKE" => "%" . $search_string . "%", "OR:content:LIKE" => "%" . $search_string . "%" ];
}

//filter by event-date
$where[] = ["event-date:>" => date('Y-m-d H:i:s')];

return json_encode($where);

Depending on your use case, something like this might be a viable replacement for SimpleSearch and is probably easier to implement than a custom postHook.

1 Like