ACF更新字段到嵌套的转发器字段中 [英] ACF Update Field into nested repeater field

查看:76
本文介绍了ACF更新字段到嵌套的转发器字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户从前端发布到嵌套的ACF转发器字段中。

I'm trying to let users post from the front end into a nested ACF repeater field.

我在第一个转发器中发布了子字段,很好。但是,我还不太清楚如何使嵌套中继器正常工作。

I've got the sub fields in the first repeater posting fine. But, I can't quite figure out how to get the nested repeater working properly.

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

Here's the code I have so far:

$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 在那里,或者如果我需要做其他事情。

I'm not sure if I can just nest another array in there, or if I need to do something else.

[更新]

我'已经做到了,它确实输入了第一行:

I've just done this and it does input into the first row:

$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

However, this code puts row 1 values both as 9 and row 2 values as 1.

因此,它看起来像:

行1:开始时间:9,结束时间:9
行2:开始时间:1 ,结束时间:1

我似乎找不到任何文档,但是看起来有可能,只是一种情况弄清楚语法。

I can't seem to find any documentation on this, but it looks like it's possible, just a case of figuring out the syntax.

推荐答案

此修复程序是一个数组数组:

The fix was an array of arrays:

$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更新字段到嵌套的转发器字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆