Problem: I would like to create a custom search filter that lets me filter posts by "age", calculated from a date in a custom field. I would like to be able to select an age range in my custom search View.
If I must filter by date range instead, I would like to show more than just 20 years in the datepicker's "year" select field.
Solution: Views can let you set up a custom search filter between two values, but those values must be custom field values or the post date. They cannot be values calculated on-the-fly. "Age" is not a custom field value - it depends on a calculation using the current date. So there is not a good way to set that up in the Views GUI. I can help you set up filters between two custom field dates, but not between two ages. That would require a significant amount of custom code that falls outside the scope of the support we provide here in the forums.
If you are comfortable writing your own code, you can use the wpv_filter_query API filter to apply a postmeta value range based on your own custom inputs. You could access the custom input values in PHP in the $_GET superglobal, and use those to calculate a start and end timestamp. Then you could apply those criteria to a meta query on your birthdate field.
If you want to filter by date range using datepickers, you can control the year range using the standard jQuery UI option "yearRange":
jQuery(document).ready(function(){ jQuery('input.hasDatepicker').datepicker('option',{'yearRange':'1990:2040'}); });
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
More info about WordPress Meta Query here:
https://codex.wordpress.org/Class_Reference/WP_Meta_Query
http://api.jqueryui.com/datepicker/#option-yearRange
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
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 4 replies, has 2 voices.
Last updated by culturaI 5 years, 2 months ago.
Assigned support staff: Christian Cox.
The forum ‘Types Community Support’ is closed to new topics and replies.