好吧,缺少更好的解决方案,我想到的是:
<?php
$today = date(\'Y-m-d\', strtotime(\'-6 hours\'));
query_posts(array(
\'post_type\' => \'events\', \'posts_per_page\' => 99, \'meta_key\' => \'event_date\', \'orderby\' => \'meta_value\', \'order\' => \'ASC\',
\'meta_query\' => array(array(
\'key\' => \'event_date\',
\'meta-value\' => $value,
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'CHAR\'
))
));
if (have_posts()) :
while (have_posts()) : the_post();
?>
以上内容获取今天日期以后的所有事件
<?php
// http://stackoverflow.com/questions/3586384/wordpress-events-grouped-by-month
// for each month output the month once
$eventdate = get_post_meta($post->ID, "event_date", true);
if(!isset($currentMonth) || $currentMonth != date("m", strtotime($eventdate))){
$currentMonth = date("m", strtotime($eventdate));
//make the month to pass into the url
$month = date("Y", strtotime($eventdate)).\'-\'.date("m", strtotime($eventdate));
$monthname = date("F", strtotime($eventdate));
?>
如果在该日期存在帖子,请将月份名称踢出一次,然后进行输出操作。
<li>
<a href="<?php echo home_url( \'/\' ); ?>whats-on-page/shows-by-month/?startdate=<?php echo($month); ?>-01&enddate=<?php echo($month); ?>-31&monthname=<?php echo ($monthname); ?>">
<?php echo ($monthname); ?>
</a>
</li>
<?php } ?>
输出html,这样我们就有了一个li和链接-链接到一个使用自定义页面模板的页面,该模板将URL中传递的参数拉入元查询,如下所示:
$start = $_GET["startdate"];
$end = $_GET["enddate"];
$monthname = $_GET["monthname"];
// gets info from URL
query_posts(array(
\'post_type\' => \'events\', //query “events”
\'posts_per_page\' => 10,
\'paged\' => $paged,
\'meta_key\' => \'event_date\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\', //sort in ascending order
\'meta_query\' => array(
array(
\'key\' => \'event_date\',
\'value\' => array($start, $end),
\'compare\' => \'BETWEEN\',
\'type\' => \'DATE\'
)
) // meta query between dates
));
if (have_posts()) :
while (have_posts()) : the_post();
因此,现在我在侧边栏中有了一个动态列表,可以链接到一个自定义页面模板,该模板按月份过滤,使用自定义日期字段有效地重新创建存档后效果。
当然,我可能会创建一些URL重写,以使这项工作与漂亮的URL太,但那是另一天。