Last active
August 29, 2015 14:06
-
-
Save jesseeproductions/f7bdd1124e9c3fed5280 to your computer and use it in GitHub Desktop.
Randomize Future Events on Main Loop of Site for The Events Calendar
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
/* | |
* 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