[Resolved] the events calendar recurrring events view
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to add a filter to show only future events from the Events Calendar plugin in a View?
Solution:
The start date is stored as in the field "_EventStartDateUTC" but it is not stored in the timestamp format used by Types date fields, and to filter by this field you will need to use the wpv_filter_query hook.
Here is an example of such code (the View ID would need editing):
i'm using "the events calendar" plugin an i have a view showing events.
i managed to get to show the event start date using the custom field "_EventStartDateUTC" - but - i can't filter with this field.
the reasons i want to filter are:
1. i want to only show future events
2. when i create a recurring event, the view treats each instances as a standalone event, then i can get about 200 events in the view. the events calendar have an option to present only the upcoming event in a series, but this option doesn't work on the view, which keeps showing me all instances.
is there any way around this?
the only solution i could think is to create a new types custom field of "start-date" and have this somehow copied from the "_EventStartDateUTC" field when a new event is created. then, these fields will be the same, but the one i created with types will be filterable.
the field is already visible and i'm using it in the view to display the date. but whenever i try to filter with it - i can 0 results.
i tried filtering it as date, datetime, number (which is the option to be used according to your documentation) - but nothing.
I looked in wp_postmeta and see that the dates are not stored as timestamps (which is how Types date fields are stored, which is why the comparison should be number), but what looks like datetime (see screenshot).
Remove the Query Filter you added in the Views GUI and add one programmatically using the wpv_filter_query hook like so:
I'm surprised it doesn't work, it works correctly on my test site, so I'm not sure what to suggest aside from make sure you edited the ID of the View, and if you are still having problems, go to Toolset > Settings > Front-end content and turn on the debug mode for Views. Then reload the page with the View and in the pop-up check the wpv_query_filter arguments have been applied, as shown in the screenshot.
In that case I'm applying some modified code where I updated the code for a date range.
If your View is showing two post types and one of the post types doesn't have the _EventStartDateUTC custom field then those posts will necessarily be excluded from the results.
dear nigel - thanks - the new code works.
unfortunately, because i really have two post types there and one doesn't have the _EventStartDateUTC custom field - i get 0 results on that type.
unless there's a way to limit your code to a certain post type (or better - a certain category within this post type) - then i'll have to let this go and just live with what i have.
thanks for all the effort - you're the best!
ido
Logically, what you want is not possible within a single query.
You are saying "show me events and articles with a future start date" but your articles have no start date so will always fail that test.
There isn't a way in a single query to say "show me articles and also show me events with a future start date", you would need two separate queries in that case, one for articles and one for events.