-
-
Save boonebgorges/5b5d6090684b2741c4ded0cca2a629b1 to your computer and use it in GitHub Desktop.
allow Tribe Events feeds to be fetched by post_date, and include start date
This file contains 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 | |
/** | |
* Custom functionality for the-events-calendar. | |
*/ | |
function cactec_is_tec_feed() { | |
if ( ! class_exists( 'Tribe__Events__Main' ) ) { | |
return false ; | |
} | |
if ( ! is_feed() || Tribe__Events__Main::POSTTYPE !== get_query_var( 'post_type' ) ) { | |
return false; | |
} | |
return true; | |
} | |
function cactec_init_feed_params( $query ) { | |
if ( ! cactec_is_tec_feed() ) { | |
return; | |
} | |
if ( ! isset( $_GET['orderby'] ) || 'post_date' !== $_GET['orderby'] ) { | |
return; | |
} | |
remove_filter( 'get_post_time', array( 'Tribe__Events__Templates', 'event_date_to_pubDate' ), 10, 3 ); | |
remove_filter( 'posts_orderby', array( 'Tribe__Events__Query', 'posts_orderby' ), 10, 2 ); | |
} | |
add_action( 'pre_get_posts', 'cactec_init_feed_params', 999 ); | |
/** | |
* Include the event start date in feeds. | |
* | |
* Since we're replacing the pubDate with the actual publication date in some | |
* cases, we must make the start date available via a different element. | |
*/ | |
function cactec_include_start_date() { | |
if ( ! cactec_is_tec_feed() ) { | |
return; | |
} | |
?> | |
<cunyAcademicCommons:eventStart><?php echo tribe_get_start_date( get_the_ID(), true, Tribe__Date_Utils::DBDATETIMEFORMAT ); ?></cunyAcademicCommons:eventStart> | |
<?php | |
} | |
add_action( 'rss2_item', 'cactec_include_start_date' ); | |
function cactec_include_cac_namespace() { | |
if ( ! cactec_is_tec_feed() ) { | |
return; | |
} | |
?> | |
xmlns:cunyAcademicCommons="https://commons.gc.cuny.edu/rss/modules/cunyAcademicCommons/" | |
<?php | |
} | |
add_action( 'rss2_ns', 'cactec_include_cac_namespace' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment