Skip Navigation

[Resolved] Pagination navigation of Events to show initially from today, but also past link

This thread is resolved. Here is a description of the problem and solution.

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 support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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 Luo Yang 6 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#628853

Tell us what you are trying to do?
Hello,
I am trying to create a cohesive calendar listing of events in Views. I currently have a simple filter set up to show 10 events equal to and greater from TODAY with pagination links for a custom date field. The previous link is initially greyed out which is expected behaviour until future events are paged through.

But I would like to also like users to be able to page through past events (with the impression its the same list/page)

Should I create a second View to filter past events and have custom links to each of the two separate views depending on when the user reaches events from today? probably yes but a second opinion is always helpful 🙂

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? I would just like an indication that it may take heavy custom coding before I continue any further to keep within the client's budget.

The link to and example of what I have started hidden link

Any direction would be appreciated!
Thanks
Todd

#629013

Dear Todd,

Yes, you are right, 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 "month" to the view, for example:
hidden link

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 by specific month:
hidden link

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

#629361

Thanks Luo,

This is great info. I just had a client meeting today and they did want a kind of dropdown with months or a next and previous month filter. They don't dislike the 10 posts at a time list but by month would be better.

I may be back next week if I have any questions but you can close this ticket.

Have a good day!

Todd

#629440

You are welcome