Tell us what you are trying to do?
Create a custom filter by month from a date field in custom post type.
Is there any documentation that you are following?
No, I can't find anything that is specific to my use case.
Is there a similar example that we can see?
I've laid out the buttons I would like to filter by here - hidden link
with the addition, the filter dates can't be shown if they are in the past.
What is the link to your site?
hidden link
Hello,
There isn't such a built-in feature within Views search form, it needs custom codes.
The custom date field created with Types plugin stores timestamp value, you can use Views filter hook to apply your own custom filter to Views query, for example:
1) When user choose option "Jan", pass URL parameter "my-month=1" to view,
2) Use Views filter hook "wpv_filter_query" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
3) In this PHP function, do these:
- get URL parameter "my-month" value,
- get the timestamp values(2019-01-01 :00:00:00 and 2019-02-01 :00:00:00) of the specific month by URL parameter "my-month"
- apply them into Views' query
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
meta_compare (string) - Operator to test the 'meta_value'. ... 'BETWEEN',
For your reference.
Currently it looks like this. (See attached images)
I am not sure where to add the custom code you have advised. Can you please provide more detail? With my current code, all workshops are displayed even when it isn't the correct month.
Thank you.
According to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/
You can contact one of Toolset certified consultants for it.
You can put your custom PHP codes into your theme file "functions.php", and in the document I mentioned above:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
There is an example for using filter hook "wpv_filter_query"
For your reference.