Advertisement
BakerMan

TEC Calendar Widget: specific cats on pages (2)

Nov 29th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. // We'll assign the slug of a specific event category to this var
  2. $calendarTerm = null;
  3.  
  4. // Have any of the pages we are interested in been requested?
  5. switch ($wp_query->post->post_name) {
  6.     case 'peewee-schedule': $calendarTerm = 'peewee'; break;
  7.     case 'bantam-schedule': $calendarTerm = 'bantam'; break;
  8.     case 'midget-schedule': $calendarTerm = 'midget'; break;
  9. }
  10.  
  11. // To help taxonomies persist over ajax requests
  12. if (defined('DOING_AJAX') and isset($_POST['customCalendarWidgetTax']))
  13.     if (!empty($_POST['customCalendarWidgetTax'])) // Not if it's empty, thanks
  14.         $calendarTerm = $_POST['customCalendarWidgetTax'];
  15.  
  16. // Basic query
  17. $calendarQuery = array('eventDisplay' => 'month');
  18.  
  19. // Create and use a tax query if we have a calendar term
  20. if ($calendarTerm !== null) {
  21.     $taxonomyQuery = array('tax_query' => array(array(
  22.         'taxonomy' => TribeEvents::TAXONOMY,
  23.         'field' => 'slug',
  24.         'terms' => $calendarTerm
  25.     )));
  26.  
  27.     $calendarQuery = array_merge($taxonomyQuery, $calendarQuery);
  28. }
  29.  
  30. // Run the query
  31. $eventPosts = tribe_get_events($calendarQuery);
  32.  
  33. // We need the category to persist across ajax requests
  34. $taxonomy = esc_attr($calendarTerm);
  35. echo '<input type="hidden" name="customCalendarWidgetTax" value="'.$taxonomy.'" />';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement