【发布时间】:2020-10-14 20:23:40
【问题描述】:
我正在开发一个足球俱乐部的 wordpress,我想显示本周的事件(比赛)。
我必须按名为“date_match”的 ACF 字段而不是帖子本身的日期进行排序,但它不起作用。
匹配是自定义帖子类型。
这是我的查询
<?php
//define args
$args = array(
'post_type' => 'matchs',
'orderby' => 'meta_value',
'meta_key' => 'date_match',
'order' => 'ASC',
'posts_per_page' => 4,
// Using the date_query to filter posts from last week
'meta_query' => array(
array(
'key' => 'date_match',
'year' => date( 'Y' ),
'week' => date( 'W' )
)
)
);
//query
$the_query = new WP_Query( $args );
//loop
if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post();
?>
…
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h6>No match to display.</h6>
</article>
<!-- /article -->
<?php endif; ?>
这是我在 ACF 中的配置:
【问题讨论】:
标签: wordpress date advanced-custom-fields custom-post-type