Wordpress acf 自定义字段日期 - 隐藏过期事件
Wordpress acf custom field date - hide expired events
这个问题已被问过很多次,并尝试了各种不同的方法,但似乎无法解决这个问题!
我有一个自定义 post 类型 'events',自定义字段 'date' 通过 acf 完成。
我可以列出所有带日期的事件并按日期排序。但我想隐藏超过当前日期的日期。我的代码是:
<?php
query_posts( array(
'post_type' => 'events',
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="event-block">
<div class="event-block-info">
<h2><?php the_title(); ?></h2>
<p><?php
$endDateText = date_i18n("d M Y", strtotime(get_field('date')));
echo $endDateText;
?></p>
<div class="event-block-image">
<?php the_post_thumbnail( 'medium' ); ?>
</div>
<div class="content">
<?php the_content(); ?>
</div>
</div>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
感谢帮助
尝试将您从 acf 字段中获得的结束事件日期与实际时间进行比较,避免打印出过去的事件。
...
if ( have_posts() ) : while ( have_posts() ) : the_post();
if(strtotime(get_field('date'))<time()){
continue;
}
?>
<div class="event-block">
.....
这个问题已被问过很多次,并尝试了各种不同的方法,但似乎无法解决这个问题!
我有一个自定义 post 类型 'events',自定义字段 'date' 通过 acf 完成。
我可以列出所有带日期的事件并按日期排序。但我想隐藏超过当前日期的日期。我的代码是:
<?php
query_posts( array(
'post_type' => 'events',
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="event-block">
<div class="event-block-info">
<h2><?php the_title(); ?></h2>
<p><?php
$endDateText = date_i18n("d M Y", strtotime(get_field('date')));
echo $endDateText;
?></p>
<div class="event-block-image">
<?php the_post_thumbnail( 'medium' ); ?>
</div>
<div class="content">
<?php the_content(); ?>
</div>
</div>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
感谢帮助
尝试将您从 acf 字段中获得的结束事件日期与实际时间进行比较,避免打印出过去的事件。
...
if ( have_posts() ) : while ( have_posts() ) : the_post();
if(strtotime(get_field('date'))<time()){
continue;
}
?>
<div class="event-block">
.....