我有一个很大的问题。我在Wordpress(WP)中打印我的活动作为自定义帖子+ acf。一切正常,但我需要对事件进行排序,以显示最顶端的事件。有没有简单的方法来做到这一点?
我的代码目前看起来像这样:
<?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>
答案 0 :(得分:1)
请添加&#39; meta_key&#39;在您的查询中,就像这样:
$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'
));
更改&#39;命令&#39; =&GT; &#39; ASC / DESC&#39;根据你的要求。
希望,这可能会对你有帮助。