Hi Christina,
Thank you for contacting us and I'd be happy to assist.
The challenge here is that the "The Events Calendar" plugin doesn't store the date values, in a standard UNIX timestamp format, that Toolset uses for date field comparisons and filters.
( https://toolset.com/documentation/user-guides/date-filters/ )
To make this work, my first recommendation would be to add a new date type custom field to the "Events" post type, so that each event's end date is available in the standard UNIX timestamp format.
1. Add a new date type custom field to the Events post type, using Toolset, e.g. "TS Event End date".
2. You can use "save_post" hook to programmatically update the value of this new custom field, matching the date from the Event Calendar plugin's "End Date" field ( _EventEndDate ):
( ref: https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/ )
function auto_update_date_field( $post_id ) {
if ( get_post_type( $post_id ) == 'tribe_events' ) {
$event_date = get_post_meta( $post_id, '_EventEndDate', true );
if(!empty($event_date)) {
$date_obj=date_create($event_date);
update_post_meta( $post_id, 'wpcf-end-date-field-slug', date_format($date_obj,"U") );
}
}
}
add_action( 'save_post', 'auto_update_date_field', 99 );
The above code can be added into the active theme's "functions.php" file and please replace "end-date-field-slug" with the actual date field slug from step 1.
As a result, when you'll enter the end date for any new or existing event in the Event Calendar's date field and save/update the event, its value will be automatically saved into the Toolset's end date field, too.
3. Next, you can create a new view to show only the last related event to a cat, based on the end date field.
( screenshot: hidden link )
Please note in the screenshot how the view is set to only show one post, which is ordered in descending order, with respect to "TS Event End date" field from step 1.
4. In the "Query Filter" section, also include a relationship filter to show only those events which are related to the current cat page.
( screenshot: hidden link )
5. In that view's content template, you can include a simple conditional block, to check if the current event's end date has lapsed or not.
[wpv-conditional if="( $(end-date-field-slug) gt 'TODAY()' )"]
Visit me at an adoption event!
[/wpv-conditional]
6. You'll insert this view in your single Cat pages so that this adoption text/button can be shown only when there is any future event available.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar