【问题标题】:Wordpress ACF: Query with sub-field repeater dateWordpress ACF:使用子字段重复日期查询
【发布时间】:2019-03-28 23:23:06
【问题描述】:

我想在我的 wordpress 网站中执行搜索,我有一个自定义帖子 (cp_course),其中包含一些自定义字段 (course_codecourse_iteration)。 Course_iteration 自定义字段是一个 Repeater 包含这些日期 sub_fields: course_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();?>

但没有运气。谁能指导我如何解决这个问题?我花了这么多天没有设法让它工作,它是如此令人沮丧。如果不容易,有没有插件可以实现?

【问题讨论】:

  • 不确定你在这方面能走多远,但你需要使用文档中提到的%$ 修复。将$where = str_replace("meta_key = 'course_iterations_%", "meta_key LIKE 'course_iterations_%", $where); 更改为$where = str_replace("meta_key = 'course_iterations_$", "meta_key LIKE 'course_iterations_%", $where);'key' =&gt; 'course_iterations_%_course_iteration_start', 更改为'key' =&gt; 'course_iterations_$_course_iteration_start',
  • 忘记添加文档链接。本页第四部分:link

标签: php wordpress search advanced-custom-fields


【解决方案1】:

据我所知,在默认 wp_queries 中,ACF 自定义字段未公开,您可以查看一下以实现您需要的内容:https://wordpress.org/plugins/acf-to-rest-api/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 2014-06-12
    • 1970-01-01
    • 2013-04-09
    • 2018-10-02
    • 2019-09-04
    • 1970-01-01
    相关资源
    最近更新 更多