SHARE
TWEET

Randomize Future Events on Main Loop of Site for The Events

jesseeproductions Aug 28th, 2014 263 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Randomize Future Events on Main Loop of Site for The Events Calendar
  3. * Setting needs to be checked to show Events on Main Loop in the Events Calendar Settings
  4. * @3.7
  5. */
  6. add_action( 'pre_get_posts', 'random_posts' );
  7. function random_posts( $query ) {
  8.                
  9.         if ( $query->is_home() && $query->is_main_query() ) {
  10.                                
  11.                $query->set( 'orderby', 'rand' );
  12.                            $query->set( 'meta_query', array(
  13.                                         array(
  14.                                                 'key' => '_EventStartDate',
  15.                                                 'value' => date('Y-m-d') . ' 00:00:00',
  16.                                                 'compare' => '>='
  17.                                         )
  18.                                         ));
  19.         }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top