Want more features on Pastebin? Sign Up, it's FREE!

The Events Calendar is_home() Conflict Workaround

By: dpellenwood on Nov 6th, 2012  |  syntax: PHP  |  size: 1.18 KB  |  views: 80  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * Setup the Index page, main query adjustments
  3.  *
  4.  * If we're viewing the site index get the first 5 posts
  5.  * from the Marquee category (home-slider), ordered
  6.  * by our meta value and ignoring any sticky stuff.
  7.  *
  8.  */
  9. function mnsu_index_query( $query ) {
  10.     if( is_home() && $query->is_main_query() ) {
  11.         if( isset( $query->query_vars['post_type'] ) && 'tribe_events' == $query->query_vars['post_type'] ) {
  12.                 /**
  13.                  * Don't do anything. We have to add this additonal check to avoid applying the query
  14.                  * modification to The Events Calendar listing pages as they set is_home() to true.
  15.                  */
  16.         } else {
  17.                         // Set paging to 5
  18.                         $query->set( 'posts_per_page', '5' );
  19.                         $query->set( 'ignore_sticky_posts', 1 );
  20.                         // Get posts from the Marquee category
  21.                         $tax_query = array (
  22.                                 array(
  23.                                         'taxonomy' => 'placements',
  24.                                         'terms' => array( 'home-slider' ),
  25.                                         'field' => 'slug',
  26.                                 )
  27.                         );
  28.                         $query->set( 'tax_query', $tax_query );
  29.                         $query->set( 'meta_key', 'mnsu_placement_home-slider' );
  30.                         $query->set( 'orderby', 'meta_value_num' );
  31.                         $query->set( 'order', 'ASC' );
  32.                 }
  33.     }
  34. }
  35. add_action( 'pre_get_posts', 'mnsu_index_query' );
clone this paste RAW Paste Data