Hello,
I have created a custom content type Event with custom fields: 'date from' and 'date to', so the user can filter the events in a chosen time period. I was able to create this view, but I would like also to display only the upcoming events.
I understand I would need to set up the query filter for the field 'date from' is greater or equal TODAY() but I can't use anymore the 'date from' field, as I have already used it for parametric search.
How can I create a view that displays upcoming events with available for the user the 'date from' filter, so he can change the date and see past event?
Best regards,
Damian
Hi, the only built-in way to set a default value for a parametric search filter in a custom search View is to use URL parameters. This means you would have to link to the page containing the View with the URL parameters already defined, like
<a href="<em><u>hidden link</u></em>">Go to Custom Search Page</a>
Unfortunately we do not have a JavaScript API available for filter manipulation, so I'm not able to provide any assistance manually controlling those filters beyond using URL parameters. We do offer wpv_filter_query and wpv_filter_query_post_process to manipulate database query criteria programmatically. More information about those APIs is available here:
https://toolset.com/documentation/programmer-reference/views-filters/
Thank you Christian, I could add the parameter and function Today() to the URL(?wpv-wpcf-data-wydarzenia=TODAY()), but the reset button would link again to the link without parameters, the same if the user would change the filter or remove the date from parametric search, so it's unfortunately not a good workaround.
What if I could create a second hidden event date field that would copy the value from the first one, something like: event_date and event_date_helper and second take the value from the first one and it's hidden for the user. I could use later this second field to filter the query.
Is it possible to achieve it with Types plugin without much coding?
Best,
Damian
but the reset button would link again to the link without parameters
Could you create a reset button or reset link that links to the correct URL? This will effectively reset the form, and I think it will be easier than manipulating filters with JavaScript. Something like:
<a href="/custom-search-page?wpv-start=123456789">Reset search</a>
What if I could create a second hidden event date field that would copy the value from the first one, something like: event_date and event_date_helper and second take the value from the first one and it's hidden for the user. I could use later this second field to filter the query.
This is difficult if your View is updated with AJAX, or if your View uses the "only show available options for inputs" feature. Complex custom JavaScript is required in these cases to keep your front-end filter in sync with the back-end filter, since they must contain different values in some cases. For simple Views that trigger page refreshes and always show all options, you might be able to do this with the wpv_filter_query API.