BakerMan

Upcoming events as month list view

Dec 28th, 2012
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. function get_specified_month($uri) {
  2.     // Look for patterns like 2099-12 at the end of the URI
  3.     $month_pattern = '[0-9]{4}-[0-9]{2}';
  4.     $optional_slash = '/?';
  5.     $pattern = "#($month_pattern)($optional_slash)$#";
  6.  
  7.     // Check for matches
  8.     $match = array();
  9.     if (preg_match($pattern, $uri, $match) !== 1) return false;
  10.  
  11.     // We are interested only in the year/date portion
  12.     return $match[1];
  13. }
  14.  
  15. function upcoming_single_month_view(WP_Query $query) {
  16.     // We are only interested in requests to view upcoming events
  17.     if ($query->query_vars['eventDisplay'] !== 'upcoming') return;
  18.  
  19.     // Has a specific month been specified?
  20.     $month = get_specified_month($_SERVER['REQUEST_URI']);
  21.     if ($month === false) return;
  22.  
  23.     // Set the start date, end date
  24.     $args = &$query->query_vars;
  25.     $args['start_date'] = $month.'-01';
  26.     $args['end_date'] = $month.'-31';
  27.  
  28.     return $query;
  29. }
  30.  
  31. // We'll run our filter later than TribeEventsQuery::setArgsFromDisplayType()
  32. add_filter('parse_tribe_event_query', 'upcoming_single_month_view', 20);
Advertisement
Add Comment
Please, Sign In to add comment