簡體   English   中英

Wordpress ACF:使用子字段中繼器日期查詢

[英]Wordpress ACF: Query with sub-field repeater date

我想在我的wordpress網站中執行搜索,該網站上有一個自定義帖子( cp_course ),其中包含一些自定義字段( course_codecourse_iteration )。 Course_iteration自定義字段是一個包含以下日期sub_fields字段的Repeatercourse_iteration_startcourse_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();?>

但是沒有運氣。 誰能指導我如何解決這個問題? 我花了很多天的時間卻沒有設法使其正常工作,而且如此令人沮喪。 如果不容易,有沒有一個插件可以實現這一目標?

據我所知,ACF自定義字段未公開,在默認的wp_queries中,您可能需要看一下才能實現所需的功能: https ://wordpress.org/plugins/acf-to-rest-api /

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM