drap5081683 2018-10-24 13:52
浏览 77

Wordpress ACF:使用子字段转发器日期查询

I want to perform a search in my wordpress site where I have a custom post (cp_course) with some custom fields (course_code, course_iteration). Course_iteration custom field is a Repeater containing these date sub_fields: course_iteration_start and course_iteration_start.

So this is what I have tried so far:

// 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();?>

But with no luck. Can anyone guide me on how to solve this? I've spent so many days on it without managing to get it to work and its so frustrating. If it's not easy is there a plugin that can achieve that?

  • 写回答

1条回答 默认 最新

  • dongwen9947 2018-10-24 19:49
    关注

    ACF custom fields are not exposed, as far as I am aware, in default wp_queries, you might have a look at this in order to achieve what you need: https://wordpress.org/plugins/acf-to-rest-api/

    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?