我当前的循环显示5个即将发生的事件,但是当事件发生的那天我无法显示那些事件帖子。这是我的代码......
<?
wp_reset_query();
query_posts(array('post_type' => 'events',
'showposts' => 5,
'meta_key'=>'event_date',
'orderby' => 'meta_value',
'order' => ASC));
while (have_posts()) : the_post();
?>
<li>
<?php $eventDate = DateTime::createFromFormat('Ymd', get_field('event_date')); ?>
<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
<span class="date"><strong>Event Date:</strong> <? echo $eventDate->format('d/m/Y'); ?></span>
</li>
<?php endwhile;?>
......任何帮助都会非常感激
答案 0 :(得分:1)
由于您的帖子有自定义字段,您可以执行以下操作:
<?php
// Get the current date
$current_date = date('M d, Y');
$current_date = strtotime( $current_date );
query_posts(array('post_type' => 'events',
'showposts' => 5,
'meta_key'=>'event_date',
'orderby' => 'meta_value',
'order' => ASC));
while (have_posts()) : the_post();
// Get the custom field
$post_date = get('date');
$post_date = strtotime( $post_date );
// If older than current date, don't show it
if( $post_date > $current_date ):
?>
<li>
<?php $eventDate = DateTime::createFromFormat('Ymd', get_field('event_date')); ?>
<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
<span class="date"><strong>Event Date:</strong> <? echo $eventDate->format('d/m/Y'); ?></span>
</li>
<?php
endif;
endwhile;
?>
希望这有帮助。