[英]Date not correct in custom Wordpress loop
I am working on a custom Wordpress loop that displays gig dates. 我正在一个自定义的Wordpress循环中显示演出日期。 Nearly everything works correctly, however I am having trouble splitting the ACF date into separate month and date span tags.
几乎所有东西都可以正常工作,但是我无法将ACF日期拆分为单独的月份和日期范围标记。
It seems to apply one date to all of the posts within the loop, instead of a separate date per post. 似乎将一个日期应用于循环中的所有帖子,而不是每个帖子使用单独的日期。
I am thinking this might be because the gig date is being fetched at the beginning? 我想这可能是因为开始时要获取演出日期? I have tried fetching the gig date within the loop but this doesn't seem to work either.
我试过在循环中获取演出日期,但这似乎也不起作用。
My loop is as follows: 我的循环如下:
<ul class="dates>
<?php
$today = date('Ymd');
$date = new DateTime(get_field('gig-date'));
$loop = new WP_Query( array(
'post_type' => 'gigs',
'showposts' => 2,
'meta_key' => 'gig-date',
'meta_compare' => '>',
'meta_value' => date("Ymd"),
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
while ( $loop->have_posts() ) : $loop->the_post(); {
?>
<li>
<div class="date">
<span class="day"><?php echo $date->format('d'); ?></span>
<span class="month"><?php echo $date->format('M'); ?></span>
</div>
</li>
<?php } endwhile; wp_reset_query(); ?>
</ul>
I adjusted my loop and placed the date request after the while loop: 我调整了循环并将日期请求放置在while循环之后:
<?php
$today = date('Ymd');
$loop = new WP_Query( array(
'post_type' => 'gigs',
'showposts' => 2,
'meta_key' => 'gig-date',
'meta_compare' => '>',
'meta_value' => date("Ymd"),
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
while ( $loop->have_posts() ) : $loop->the_post(); {
$date = get_field('gig-date', false, false);
$date = new DateTime($date);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.