繁体   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