Problem:
Right now my set up is simple, with the 10 event paged like regular posts, but I am afraid the client may want a monthly dropdown to select only events from that month or the previous and next to be the "previous month" or "next month" with the month names like a real calendar.
Is this possible with Views from an event custom date field?
Solution:
There are not such kind of built-in features within Views plugin, it needs custom codes.
Here are my suggestions:
1) You can setup the monthly dropdown, "previous month" or "next month" to pass URL parameter "my-month" to the view, for example:
http://my-site-url/?my-month=2018-03
It will be able to pass URL parameter "my-month", value is 2018-03,
2) use Views filter hook "wpv_filter_query" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
get the URL parameter "my-month" value: $_GET['my-month'],
calculate the timestamp values of the start and end of the specific month:
http://php.net/manual/en/ref.datetime.php
3) Then use above values to add filter on the custom date field "Event date":
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
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 |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
This topic contains 3 replies, has 2 voices.
Last updated by 6 years, 9 months ago.
Assisted by: Luo Yang.