Skip Navigation

[Resolved] Filter posts by decade from year CF

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by christopheM 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#613482

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

#613545

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

#615000

Hi Christian,

I found an alternate solution for this to be what i wanted, so i'm ok.

Thanks