我想要实现的是通过get\\u post\\u meta获取日期,并将其推送到数组中,然后将其传递到js代码中。但当我使用下面的代码时,循环中的第一篇帖子的日期会被格式化,而其他帖子的日期显示为1970年1月1日。工作时间为5小时,如有任何帮助,将不胜感激。
这是wordpress的代码。
<?php
function bpem_event_calendar_tab() {
global $bp;
if (isset($bp->groups->current_group->slug)) {
bp_core_new_subnav_item(array(
\'name\' => \'Event Calendar\',
\'slug\' => \'events-calendar\',
\'parent_slug\' => $bp->groups->current_group->slug,
\'parent_url\' => bp_get_group_permalink($bp->groups->current_group),
\'screen_function\' => \'bpem_event_calendar_roup_show_screen\',
\'position\' => 90));
}
}
add_action(\'wp\', \'bpem_event_calendar_tab\');
function bpem_event_calendar_roup_show_screen() {
//add_action(\'bp_template_title\', \'ev_new_group_show_screen_title\');
add_action(\'bp_template_content\', \'bpem_event_calendar_group_show_screen_content\');
$templates = array(\'groups/single/plugins.php\', \'plugin-template.php\');
if (strstr(locate_template($templates), \'groups/single/plugins.php\')) {
bp_core_load_template(apply_filters(\'bp_core_template_plugin\', \'groups/single/plugins\'));
} else {
bp_core_load_template(apply_filters(\'bp_core_template_plugin\', \'plugin-template\'));
}
}
/*function ev_new_group_show_screen_title() {
echo \'New Tab Title\';
}*/
function bpem_event_calendar_group_show_screen_content() {
$group_name = sanitize_title(bp_get_current_group_name());
$event_data = array();
$args = array(
\'post_type\' => \'bpem_event\',
\'posts_per_page\' => -1,
/* \'meta_key\' => \'evn_group_slug\',
\'meta_value\' => $group_name,*/
);
$i=0;
$event_query = new WP_Query( $args );
if ( $event_query->have_posts() ) : while ( $event_query->have_posts() ) :
$event_query->the_post();
$start_date = get_post_meta( get_the_id(), \'evn_startDate\');
//print_r($start_date);
$start_d = date("Y-m-d", strtotime($start_date[$i]));
//echo $start_d.\'<br>\';
$start_time = get_post_meta(get_the_id(), \'evn_startTime\');
$start_t = date("H:i:s", strtotime($start_time[$i]));
$end_date = get_post_meta( get_the_id(), \'evn_endDate\');
//print_r($end_date);
$end_d = date("Y-m-d", strtotime($end_date[$i]));
//echo $end_d;
$end_time = get_post_meta(get_the_id(), \'evn_endTime\');
$end_t = date("H:i:s", strtotime($end_time[$i]));
$event_data[] = array(
\'title\' => get_the_title(),
\'start\' => $start_d.\'T\'.$start_t,
\'end\' => $end_d.\'T\'.$end_t
//\'end_date\' => $enddate[0]
);
$i++;
endwhile;
wp_reset_postdata();
endif;
$json = json_encode($event_data);
print_r($json);
echo "<div id=\'bpem-calendar\'></div>";
?>
<script type="text/javascript">
jQuery(document).ready(function() {
var todayDate = jQuery.datepicker.formatDate(\'yy-mm-dd\', new Date());
jQuery(\'#bpem-calendar\').fullCalendar({
header: {
left: \'prev,next today\',
center: \'title\',
right: \'month,agendaWeek,agendaDay\'
},
defaultDate: todayDate,
businessHours: true, // display business hours
editable: false,
events:<?php echo json_encode($event_data); ?>
});
});
</script>
<?php
} ?>
这是输出。
[{“title”:“JSON专家会议”,“start”:“2019-03-25T07:00:00”,“end”:“2019-03-27T09:30:00”},{“title”:“WordPress Meetup Karachi”,“start”:“1970-01-01T00:00:00”,“end”:“1970-01-01T00:00:00”},{“title”:“WP Meetup Karachi”,“start”:“1970-01-01T00:00:00”,“end”:“1970-01-01T00:00:00”},{“title”:“JQuery大师会议”,“start”:“1970-01-01T00:00:00”-01-01T00:00:00,“结束”:“1970-01-01T00:00:00”}]