我正在一个wordpress网站上工作,该网站将只查询即将到来的事件(自定义帖子类型)。我已经知道了如何只显示即将发生的事件,但我想允许用户在单击我使用wp\\u get\\u archives创建的归档选项卡时查看过去的事件。现在,当您选择像“2013”这样的存档年份时,它会输出相同的“即将发生的事件”查询,但我想输出2013年的所有事件。我怎么会这样?
$today = date(\'Ymd\');
$paged = ( get_query_var(\'paged\') == 0 ) ? 1 : get_query_var(\'paged\');
$posts = new WP_Query(array(
\'post_type\' => \'event\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 5,
\'meta_key\' => \'new_start_date\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'new_start_date\',
\'compare\' => \'>=\',
\'value\' => $today,
\'type\' => \'DATE\'
),
),
\'paged\' => $paged
));
<div class="my-pa_archive_post-year">
<?php
$args = array(
\'type\' => \'yearly\',
\'limit\' => \'\',
\'format\' => \'html\',
\'before\' => \'\',
\'after\' => \'\',
\'show_post_count\' => false,
\'echo\' => 1,
\'order\' => \'DESC\',
\'post_type\' => \'event\',
);
wp_get_archives( $args );
?>
</div>
SO网友:stillatmylinux
代替$today = date(\'Ymd\')
具有
$hour = 0;
$minute = 0;
$second = 0;
$month = (is_month()) ? get_the_date(\'m\') : 1;
$day = (is_day()) ? get_the_date(\'d\') : 1;
$year = get_the_date(\'Y\');
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
$search_date = date(\'Ymd\', $timestamp);
// echo $search_date;
在查询中,替换
\'value\' => $today,
具有
\'value\' => $search_date,