ACF更新域到嵌套Repeater场(ACF Update Field into nested re

2019-10-20 03:55发布

我试图让用户从前端到嵌套ACF转发后场。

我得在第一中继发布精细的子领域。 但是,我不能完全弄清楚如何让嵌套的中继器工作正常。

这里是我到目前为止的代码:

$event_field_key = 'field_535e6b9ffe3da';

$events[] = array(
    'start-date'   => $startDate,
    'end-date'     => $endDate,
    'notes'          => $_POST['p'.$p.'-notes'],
    'start-end-times' => array(
        'start-time' => '09:00', // would be dynamic
        'end-time' => '17:00' // would be dynamic
    )
);

update_field($event_field_key, $events, $post_id);

我不知道如果我可以嵌套另一个array在那里,或者如果我需要做些别的事情。

[UPDATE]

我只是这样做,它输入到第一行:

$event_field_key = 'field_535e6b9ffe3da';

$events[] = array(
    'start-date'   => $startDate,
    'end-date'     => $endDate,
    'notes'          => $_POST['p'.$p.'-notes'],
    'start-end-times' => array(
       'start-time' => '9:00',
       'end-time' => ' 17:00'
    )
);

update_field($event_field_key, $events, $post_id);

然而,这种代码使第1倍的值既作为9和行2倍的值作为1

所以它看起来像:

Row 1: start time: 9, end time: 9 Row 2: start time: 1, end time: 1

我似乎无法找到任何这文件,但看起来这是可能的,只是找出语法的情况。

Answer 1:

定盘数组的数组:

$event_field_key = 'field_535e6b9ffe3da';

        $events[] = array(
            'start-date'   => $startDate,
            'end-date'     => $endDate,
            'notes'          => $_POST['p'.$p.'-notes'],
            'start-end-times' => array(
                array(
                    'start-time' => '09:00',
                    'end-time' => '17:00'
                ),
                array(
                    'start-time' => '10:00',
                    'end-time' => '16:00'
                )
            )
        );

        update_field($event_field_key, $events, $post_id);


文章来源: ACF Update Field into nested repeater field