-
-
Save ethanclevenger91/cb7b804eee78e1d7f0083160a0e68959 to your computer and use it in GitHub Desktop.
The Events Calendar Get Events for 1 Year from Today in iCal Export File -- http://example.com/events/?ical=1&year-feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// From https://gist.github.com/cliffordp/ab1f7c4d95723ee6f892/, a fork of https://gist.github.com/jesseeproductions/2b1af6527b7029eaea6e | |
// References: | |
// https://theeventscalendar.com/support/forums/topic/ical-only-pushing-1-month-at-a-time/ | |
// https://theeventscalendar.com/support/forums/topic/how-users-can-subscribe-to-my-events-calendar-in-their-personal-calendars/#post-1022932 | |
// https://tribe.uservoice.com/forums/195723-feature-ideas/suggestions/3777092-subscribe-to-calendar-via-ical | |
/* | |
* The Events Calendar Get Events for 1 Year from Today in iCal Export File | |
* add coding to child theme's functions.php | |
* Tested works with The Events Calendar v3.12 and v4.0 | |
* trigger export with link: http://example.com/events/?ical=1&year-feed | |
* change 365 for a different range | |
*/ | |
// See https://gist.github.com/cliffordp/b0e5ece86040d9838f09 to customize text of iCal Event Export button text | |
// See https://gist.github.com/cliffordp/0add8931e1c6422a7b4c to override the iCal link to always be this link | |
add_action( 'pre_get_posts', 'cliff_tribe_custom_time_range_ics_export' ); | |
function cliff_tribe_custom_time_range_ics_export( WP_Query $query ) { | |
if ( ! isset( $_GET['ical'] ) || ! isset( $_GET['year-feed'] ) ) { | |
return; | |
} | |
if ( ! isset( $query->tribe_is_event_query ) || ! $query->tribe_is_event_query ) { | |
return; | |
} | |
$query->set( 'eventDisplay', 'custom' ); | |
$query->set( 'start_date', 'now' ); | |
$query->set( 'end_date', '+ 365 days' ); // http://php.net/manual/en/datetime.formats.relative.php | |
// This will get railroaded by $count in iCal.php `get_events_list`, which can't be set to a negative number. | |
$query->set( 'posts_per_page', -1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment