Wondering how to use add_rows (or something similar) to add an entry to a flexible content field programmatically. On ACF's website they mention add_rows can be used to add a row to a flexible content field https://www.advancedcustomfields.com/resources/ but they give no examples how to do it with a flexible content field; only with a repeater field. Thanks!
1条回答 默认 最新
- douguabu8960 2018-09-27 06:59关注
use
add_row( $selector, $value, $post_id )
This function will add a new row of data to an existing repeater field field value.$selector: (required) The parent field name or key
$value: (required) The new value to append
$post_id: (optional) The post ID of which the value is saved to. Defaults to current post Return
Below is the example that how you can add
image
filed with multiple values<?php $row = array( 'image' => 123, 'alt' => 'Another great sunset', 'link' => 'http://website.com' ); $i = add_row('images', $row); ?>
To Add repeater field in flexible content you should use below code :
<?php $field_key = "flexible_content_field_key"; $value = array( array( "sub_field_1" => "Foo1", "sub_field_2" => "Bar1", "acf_fc_layout" => "layout_1_name" ), array( "sub_field_x" => "Foo2", "sub_field_y" => "Bar2", "acf_fc_layout" => "layout_2_name" ) ); update_field( $field_key, $value, $post_id ); ?>
Here
acf_fc_layout
is used to add sub fields for image hereimage
is flexible content field key where in your case there will be your flexible content key.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器