Skip to content

Instantly share code, notes, and snippets.

@caseydriscoll
Created July 15, 2014 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseydriscoll/45acdda5a7b3de558941 to your computer and use it in GitHub Desktop.
Save caseydriscoll/45acdda5a7b3de558941 to your computer and use it in GitHub Desktop.
Tribe Events One Week Back
// 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