Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Last active August 29, 2015 14:06
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 jesseeproductions/f7bdd1124e9c3fed5280 to your computer and use it in GitHub Desktop.
Save jesseeproductions/f7bdd1124e9c3fed5280 to your computer and use it in GitHub Desktop.
Randomize Future Events on Main Loop of Site for The Events Calendar
/*
* Randomize Future Events on Main Loop of Site for The Events Calendar
* Setting needs to be checked to show Events on Main Loop in the Events Calendar Settings
* @3.7
*/
add_action( 'pre_get_posts', 'random_posts' );
function random_posts( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'rand' );
$query->set( 'meta_query', array(
array(
'key' => '_EventStartDate',
'value' => date('Y-m-d') . ' 00:00:00',
'compare' => '>='
)
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment