Created
July 15, 2014 16:42
-
-
Save caseydriscoll/45acdda5a7b3de558941 to your computer and use it in GitHub Desktop.
Tribe Events One Week Back
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
// Written by Barry Hughes of Modern Tribe | |
add_action( 'pre_get_posts', 'include_events_one_week_prior', 200 ); | |
function include_events_one_week_prior( $query ) { | |
// Avoid fatals if TEC is deactivated | |
if ( ! class_exists( 'TribeEvents' ) ) return; | |
// Is it an events query? | |
if ( $query->get( 'post_type' ) !== TribeEvents::POSTTYPE ) return; | |
// Is it for list view/photo view? | |
$acceptable = array( 'photo', 'upcoming' ); | |
if ( ! in_array( $query->get( 'eventDisplay' ), $acceptable ) ) return; | |
// If we're within a paginated result set, don't interfere | |
if ( $query->get( 'paged' ) > 0 ) return; | |
// Calculate the date one week back from now | |
$start_date = date_i18n( TribeDateUtils::DBDATETIMEFORMAT, strtotime( '-1 week' ) ); | |
// Adjust the query | |
$query->set( 'start_date', $start_date ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment