[英]Wordpress ACF: Query with sub-field repeater date
我想在我的wordpress網站中執行搜索,該網站上有一個自定義帖子( cp_course
),其中包含一些自定義字段( course_code
, course_iteration
)。 Course_iteration
自定義字段是一個包含以下日期sub_fields
字段的Repeater
: course_iteration_start
和course_iteration_start
。
因此,這是我到目前為止嘗試過的:
// filter
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'course_iterations_%", "meta_key LIKE 'course_iterations_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array(
'post_type' => 'cp_course', 'numberposts' =>-1,'orderby' => 'ID', 'order' => 'ASC', 's' => $searchterm,
'meta_query' =>
array(
'relation' => 'AND',
array(
'key' => 'course_code',
'value' => $code,
),
array(
'key' => 'course_duration',
'value' => $duration,
),
array(
'key' => 'course_iterations_%_course_iteration_start',
'compare' => 'between',
'type' => 'numeric',
'value' => array($date_from, $date_to),
)
)
);
$course = get_posts($args);
<div class="page_title">
<h3>Courses</h3>
</div>
<?php foreach ($course as $post):setup_postdata($post);?>
<a href="#"><?php the_title();?></a>
<?php endforeach;wp_reset_postdata();?>
但是沒有運氣。 誰能指導我如何解決這個問題? 我花了很多天的時間卻沒有設法使其正常工作,而且如此令人沮喪。 如果不容易,有沒有一個插件可以實現這一目標?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.