我正在使用自定义查询在Wordpress中构建Tribe Event Calendar自定义轮播查询(wP_Query)。我的事件查询效果很好,但是我想显示没有安排任何事件的空日期。有可能吗?还是有解决方法?任何帮助将不胜感激!
我的查询代码:
$args = array(
'post_status'=>'publish',
'post_type'=>array(TribeEvents::POSTTYPE),
'posts_per_page'=>10,
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-1 week' ) ),
'end_date' => date( 'Y-m-d H:i:s', strtotime( '+1 month' ) ),
//order by startdate from newest to oldest
'meta_key'=>'_EventStartDate',
'orderby'=>'_EventStartDate',
'order'=>'ASC',
//required in 3.x
'eventDisplay'=>'custom',
);
$get_posts = null;
$get_posts = new WP_Query();
$get_posts->query($args);
if($get_posts->have_posts()) {
while($get_posts->have_posts()) : $get_posts->the_post();
// display results here from loop
endwhile;
}
wp_reset_query();
更新: 我发现此脚本可能有效。然后我可以弄乱日期的格式。我相信我只是在考虑实际问题。一旦弄明白了,我将提供一个工作代码。
$start_date = '2012-01-01'; /* I can change this to strtotime( '-1 week' ) */
$end_date = '2012-12-31'; /* and this to strtotime( '+1 month' ) but mess with the format in PHP Y-m-d */
$start = new DateTime($start_date);
$end = new DateTime($end_date);
$interval = new DateInterval('P1D'); // 1 day interval
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $day) {
// Do stuff with each $day...
echo $day->format('Y-m-d'), "\n";
}