Date Range Filtering

Permalink
Hi Guys
Would anyone know if it is possible to filter a page list by date range. For example
This Month
Next 3 months
Next 6 months
Next 12 months
Over 12 Months
I am using the page list to list events. Each event has a custom start date and time. It will be that date which the events will be filtered by.

 
hutman replied on at Permalink Reply
hutman
I don't know that this will work with the PageList block, but you could build your own block and use the PageList model. Something like this, which would get you events with a date starting now for the next 30 days.

$pl = new PageList();
$pl->filterByPageTypeHandle("your_page_type_handle");
$pl->filterByAttribute('attribute_handle', date('Y-m-d H:i:s'), '>');
$pl->filterByAttribute('attribute_handle', date('Y-m-d H:i:s', strtotime('+30 days')), '<=');
$pl->sortByPublicDateDescending();
$pagination = $pl->getPagination();
$events = $pagination->getCurrentPageResults();
JackVanson replied on at Permalink Reply
Thanks for the reply!

This is great a big step forward in making this happen.

One question. How would I make it so the front end site user can use these options to filter the page list. For example have these date ranges in a select box. When the users selects an option the page list updates.

Thanks

Jack
hutman replied on at Permalink Reply 1 Attachment
hutman
If this was me I would do it as an external form and on the form I would put the select element with the date range options, then have it submit to another function to do the filtering. I've attached an example external form for you to test out.

I haven't tested this code so there might be some mistakes, but it should give you an idea.
Gondwana replied on at Permalink Reply
Gondwana
This probably isn't directly relevant, but there's some interesting-looking date-related code in the search block controller's do_search():
https://github.com/concrete5/concrete5/blob/8.1.0/concrete/blocks/se...

I'm not sure it's actually relevant any more because it doesn't appear to relate to any documented feature of the search block.