This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Filter by year (custom dropdown)

#47960
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

If by any chance the date is stored in a mysql datetime format, or something similar to that – and not as timestamp – then there might be a way to achieve that without a single line of code.

The idea is to treat the datetime field as a “string”. Datetime is stored like 2024-12-31 23:59:59 – which is very lucky for us, as the year is the only 4 digit string to match.

Therefore creating a drop-down/radio/checkbox filter with simply the year values like this will actually match the year: https://i.imgur.com/P5zdZvQ.png
If the field is stored as datetime, this will always match the year, as it’s the only 4 digit value in the field.

Doing a range type with this method is not possible. However if you were have a separate custom field to only store the year, then you will be able to also use the range slider filter as well.