I use FullCalendar to load events from custom message types in WP via the JSON channel. It works, but it takes some time to load. Please check here: http://cea3.iscte.pt/en/agenda-3/ (June or August). Do any of you have a clue on what could be causing?
This is the complete code for the JSON channel:
<?php
header('Content-Type:application/json');
if(file_exists('../../../../wp-load.php')) :
include '../../../../wp-load.php';
else:
include '../../../../../wp-load.php';
endif;
global $wpdb;
$oneyear = strtotime('-1 year') + ( get_option( 'gmt_offset' ) * 3600 );
global $wpdb;
$querystr = "
SELECT *
FROM $wpdb->posts wposts, $wpdb->postmeta metastart, $wpdb->postmeta metaend
WHERE (wposts.ID = metastart.post_id AND wposts.ID = metaend.post_id)
AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $oneyear )
AND metastart.meta_key = 'tf_events_enddate'
AND wposts.post_type = 'tf_events'
AND wposts.post_status = 'publish'
ORDER BY metastart.meta_value ASC LIMIT 500
";
$events = $wpdb->get_results($querystr, OBJECT);
$jsonevents = array();
if ($events):
global $post;
foreach ($events as $post):
setup_postdata($post);
$custom = get_post_custom(get_the_ID());
$sd = $custom["tf_events_startdate"][0];
$ed = $custom["tf_events_enddate"][0];
$gmts = date('Y-m-d H:i:s', $sd);
$gmts = get_gmt_from_date($gmts);
$gmts = strtotime($gmts);
$gmte = date('Y-m-d H:i:s', $ed);
$gmte = get_gmt_from_date($gmte);
$gmte = strtotime($gmte);
$stime = date('c', $gmts);
$etime = date('c', $gmte);
$thetitle = $post->post_title;
$short_title = substr($thetitle,0,50);
$eventpostid = $post->ID;
$eventslug = wp_get_post_terms( $eventpostid, 'tf_eventcategory' );
$eventvenueslug = $eventslug[0]->slug;
$tf_events_link = get_post_meta($post->ID, 'tf_events_link', true);
$tf_events_permalink = get_permalink($post->ID);
if ($tf_events_link) { $url_event = $tf_events_link ; }
else { $url_event = $tf_events_permalink; };
$jsonevents[]= array(
'title' => $short_title . '...',
'allDay' => false,
'start' => $stime,
'end' => $etime,
'url' => $url_event,
'className' => $eventvenueslug
);
endforeach;
else :
endif;
echo json_encode($jsonevents);
?>
Thank.
source
share