Dear Sir/Madam,
I have an event custom post with start and end date, I want to have a dropdown select from Jan to Dec to filter the event where the start or end date is in the selected month, how can I make the filter using url parameter?
Best regards,
Kelvin.
Dear Kelvin.
I assume we are talking about filter by post published date, it is possible, please check our document:
https://toolset.com/documentation/user-guides/filtering-views-query-by-date/
You can also set the values to come from external parameters, using the two classical ways to pass information into a View: a shortcode attribute or an URL parameter.
Dear Luo Yang,
Sorry I am not using the publish date for the filter, I create the custom post with custom date field.
Best regards,
Kelvin
Custom date field is also a custom field, so you can follow our document to make the filter using url parameter:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
section "Source for compare value":
URL parameter
The value for the filter is set in the URL to the page
This will let you create custom searches filters for Views, where visitors can control what the View will show.
But in the parameter search form of Views plugin, the custom date field displays as a datepicker, there isn't such an option to display it as select dropdown menu, you will need to try with custom codes to add the filters, for example:
Views filter hook "wpv_filter_query"
https://toolset.com/documentation/user-guides/views-filters/#wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.
Hope it help
Dear Luo,
Sorry I have no idea how the wpv_filter_query be applied in the View filter, could you show some example to archive my requirement?
Best regards,
Kelvin
There is a misunderstand, in Views parameter filter form, the custom date field is display as a datepicker, there isn't such an option to display as a dropdown menu, if you need the dropdown menu, you will need try with custom PHP codes:
1) Create a dropdown menu to pass URL parameter to the view,
2) turn the URL parameter into time stamp value, for example PHP function strtotime()
hidden link
3) Then add filters to your view with the filter hook "wpv_filter_query"
There are lots of examples of using the filter hook "wpv_filter_query", in out document, there is an example:
https://toolset.com/documentation/user-guides/views-filters/#wpv_filter_query
And
hidden link
Hope it help