Hello,
I'm trying to add a filter to show post results by decade (ex: 1950-1960 or The 50s)
The thing is, the custom field used in the filter only has a year in it.
Is there any way to create a dropdown filter that will automatically create decades ?
(So if the field contain 1974, the filter shows "1970-1980")
Thanks
Hi, there's not a good way to automatically generate something exactly like this, but we offer another way to accomplish something similar. A custom search filter can filter based on a custom field and compare it to two values using "between". In other words you could include two select field filters, and each filter would include options that represent decades. One filter would choose the starting decade, and the other would choose the ending decade. Your users could select "50s" and "60s" to see all results with custom fields between the values 1950 and 1960.
If that's acceptable, I can help you configure this using custom field filters. Otherwise, I think you will have to set up some custom code using the wpv_filter_query API that applies a range filter based on the User's selected filter values. You would have to create a custom filter select box representing all the possible ranges. Let me know how you would like to proceed.
More info about filtering by custom fields here:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
More info about the wpv_filter_query API here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Hi Christian,
I found an alternate solution for this to be what i wanted, so i'm ok.
Thanks