[英]Get closest date compared to current date ACF
I have a huge question. 我有一个很大的问题。 I am printing out my events in Wordpress (WP) as custom post + acf. 我将在Wordpress(WP)中将事件打印为自定义帖子+ acf。 Everything works fine but I need to sort my events to show the closest events at the top. 一切正常,但我需要对事件进行排序以在顶部显示最近的事件。 Is there any easy way to do this? 有没有简单的方法可以做到这一点?
My Code looks like this currently: 我的代码当前如下所示:
<?php
/*
Template Name: Program Template
*/
$today = date('Ymd');
$query = new WP_Query(array(
'post_type' => 'program',
'post_status' => 'publish'
));
get_header(); ?>
<div id="particle-canvas">
<h1 class="page-title">Program</h1>
</div>
<div class="container-fluid program">
<div class="row">
<?php while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID(); ?>
<div class="col-md-6 program__program-content">
<div class="overlay-box">
<span><?php $date_value = get_field('date', $post_id);
echo date('d/m/Y', strtotime($date_value)); ?></span>
<img src="<?php the_post_thumbnail_url(array(645, 246)); ?>" alt="">
<div class="details">
<h3><?php echo get_the_title(); ?></h3>
<div class="button">
<a href="<?php echo get_permalink(); ?>">
<p>More</p>
</a>
</div>
</div>
</div>
</div>
<?php } ?>
<?php wp_reset_query(); ?>
</div>
</div>
Please add 'meta_key' in your query, just like this: 请在查询中添加“ meta_key”,如下所示:
$query = new WP_Query(array(
'post_type' => 'program',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'date',
'meta_type' => 'DATE',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Change the 'order' => 'ASC/DESC' according to your requirement. 根据您的要求更改'order'=>'ASC / DESC'。
Hope, this may help you. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.