Advertisement
BakerMan

Mix Events with WP Posts and RSS Feeds

Sep 25th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. /**
  2.  * Change the main query on the homepage and in non-Events RSS feeds so that
  3.  * event posts are included in the results.
  4.  *
  5.  * @param WP_Query $query
  6.  * @return WP_Query
  7.  */
  8. function eventPostMixin(WP_Query $query) {
  9.     // Don't do anything on an event page (tribe_is_event() will not provide the
  10.     // result you expect before the main query has finished executing)
  11.     if (array_key_exists('eventDisplay', $query->query_vars)) return $query;
  12.  
  13.     // Add Tribe Events to the main homepage query and to any non-Tribe RSS
  14.     // feeds
  15.     if  ((is_home() and $query->is_main_query()) or (is_feed() and !tribe_is_event()))
  16.         $query->set('post_type', array('post', 'page', TribeEvents::POSTTYPE));
  17.  
  18.     return $query;
  19. }
  20.  
  21. add_filter('pre_get_posts', 'eventPostMixin');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement