使用 wordpress 和高级自定义字段,如何为我的元查询使用子字段?

Using wordpress and advanced custom fields, how can I use a subfield for my meta query?

我将 Wordpress 与 Advanced Custom Fields Pro 插件一起使用,我正在尝试获取日期字段晚于今天日期的所有帖子。我查看了这个示例 https://www.advancedcustomfields.com/resources/date-picker/ and that works fine except that my field is a subfield of a repeater field. And I have some trouble making a meta query for that. I tried using _%_ for the subfield but then I read here https://support.advancedcustomfields.com/forums/topic/meta_query-for-a-group-field-sub-field/ that I can just use an underscore for the subfield. But posts still aren't coming up with any results. I tried checking the date from just a single post and it appears to be working correctly. I also read here advancedcustomfields.com/resources/date-picker,日期在数据库中始终存储为 Ymd。我试着用另一个不是子字段的字段来做,但它起作用了,所以问题出在我认为的子字段上 'key' => 'date_startdate',

我正在使用日期选择器作为子字段。

function do_get_upcoming($atts = [])
    {
        $defaultLimit = 8;
        $limit = $atts["limit"] != null ? $atts["limit"] : $defaultLimit;

        $today = date('Ymd');

        $posts = get_posts(array(
            'numberposts'   => $limit,
            'post_type'     => 'events',
            'meta_query' => array(
                 array(
                    'key'     => 'date_startdate',
                    'value'   => $today,
                    ‘type’ => ‘DATE’
                    'compare' => '>',
                )
            ),
        ));

        echo count($posts);
    }
    add_shortcode('get_upcoming','do_get_upcoming');

screenshot subfield

我找到了解决方案。可以通过添加 _0_ 来访问子字段,因此您将获得 'key' => 'date_0_startdate'