custom-post-type
function get_vacation_dates(){
global $post;
$args = array(
'post_type' => array('vacationperiods'),
'post_status' => array('publish'),
'order' => 'ASC'
);
$posts = get_posts($args);
$vac = [];
foreach ($posts as $post){
$vacationTitle = get_field('name', $post->ID);
$startDate = get_field('vacation_start', $post->ID);
$endDate = get_field('vacation_end', $post->ID);
// GET ALL DAYS/DATES
for ($i=$startDate; $i<=$endDate; $i+=86400) {
$days = date('Y-m-d', $i);
}
$duration = dateDiff($startDate, $endDate);
$vac[] = [
'name' => $vacationTitle,
'start' => $startDate,
'end' => $endDate,
'duration' => $duration,
'days' => $days
];
}
echo json_encode($days);
die();
}
这种方法不起作用,它给我
"days: '1970-01-01'"
['2018-09-13', '2018-09-14', etc..]
我怎样才能做到这一点?