Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.