Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Forked from jesseeproductions/tribe-ical-one-year.php
Last active September 26, 2021 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cliffordp/ab1f7c4d95723ee6f892 to your computer and use it in GitHub Desktop.
Save cliffordp/ab1f7c4d95723ee6f892 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
<?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
$query->set( 'posts_per_page', -1 );
}
@amandablum
Copy link

Hey, any chance of a post 5.0 Event Cal update to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment