遵循上的高级示例https://www.advancedcustomfields.com/resources/date-picker/ 这对我很有用:
有一个名为“event”的帖子类型,其中包含两个acf自定义字段“event\\u date\\u start”和“event\\u date\\u end”。
该查询显示从今天开始的所有未来事件,每个月都会获得其标题。因此,可以说事件是按月份分组的。也许这不是你想要的,但至少这可能是一个有趣的方法。。。
March 2017
-事件1
-事件2
-事件3
April 2017
-事件4
-事件5
。。。
<?php
$today = date(\'Ymd\');
$args = array(
\'post_type\' => \'event\',
\'posts_per_page\' => -1,
\'meta_key\' => \'event_date_start\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'event_date_end\' ,
\'compare\' => \'>=\',
\'value\' => $today,
\'type\' => \'date\'
),
array(
\'key\' => \'event_date_start\' ,
\'compare\' => \'>=\',
\'value\' => $today,
\'type\' => \'date\'
),
)
);
$shows = get_posts($args );
$current_header = \'\';
foreach ($shows as $post ) : setup_postdata($post);
// get raw date
$date = get_field(\'event_date_start\', false, false);
$temp_header = date_i18n(\'F Y\', strtotime($date));
if ( $temp_header != $current_header ) {
$current_header = $temp_header;
echo "<h3>".$current_header.\'</h3>\';
}
// echo content of event
get_template_part(\'templates/content\', \'events\');
endforeach;
wp_reset_postdata();
?>