Advertisement
Guest User

JSON Full Calendar Paste

a guest
May 10th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type:application/json');
  4.  
  5. if(file_exists('../../../../wp-load.php')) :
  6.     include '../../../../wp-load.php';
  7. else:
  8.     include '../../../../../wp-load.php';
  9. endif;
  10.  
  11. //$today6am = strtotime('today 6:00') + ( get_option( 'gmt_offset' ) * 3600 );
  12.  
  13. global $wpdb;
  14.  
  15. $args = array(
  16.               'posts_per_page'  => -1,
  17.               'orderby'         => 'post_date',
  18.               'order'           => 'DESC',
  19.               'post_type'       => 'course',
  20.               'meta_key'        => '_uni_course-dates-start',
  21.               );
  22. $events = get_posts( $args );
  23. $jsonevents = array();
  24. if ($events):
  25. global $post;
  26. foreach ($events as $post):
  27. setup_postdata($post);
  28.  
  29. // - custom post type variables -
  30. $custom = get_post_custom(get_the_ID());
  31. $sd = $custom["_uni_course-dates-start"][0];
  32. $ed = $custom["_uni_course-dates-end"][0];
  33.  
  34. // - grab gmt for start -
  35. $gmts = date('Y-m-d H:i:s', $sd);
  36. //$gmts = get_gmt_from_date($gmts); // this function requires Y-m-d H:i:s
  37. $gmts = strtotime($gmts);
  38.  
  39. // - grab gmt for end -
  40. $gmte = date('Y-m-d H:i:s', $ed);
  41. //$gmte = get_gmt_from_date($gmte); // this function requires Y-m-d H:i:s
  42. $gmte = strtotime($gmte);
  43.  
  44. // - set to ISO 8601 date format -
  45. $stime = date('c', $gmts);
  46. $etime = date('c', $gmte);
  47.  
  48. $term = get_single_term($post->ID, 'course_locations');
  49.  
  50.     //$year = date('Y');
  51.     //$month = date('m');
  52.  
  53. // - json items -
  54. $jsonevents[]= array(
  55.     'title' => $post->post_title,
  56.     'allDay' => false, // <- true by default with FullCalendar
  57.     'start' => $stime,
  58.     //'end' => $etime,
  59.     'className' => $term,
  60.     'url' => get_permalink($post->ID)
  61.     );
  62.  
  63. endforeach;
  64. else :
  65. endif;
  66.  
  67. // - fire away -
  68. echo json_encode($jsonevents);
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement