As the title suggests, I have this kind of structure:
flexible_content (Flexible content)
-accordion (Layout)
--accordion_item (Repeater)
---title (text)
---content (wysiwyg)
I have a external database from which I want to insert a number of accordions. How can I do that programmatically with PHP? I have created a loop after getting the data from DB and want to run insert functionality inside the loop.
I added the "accordion" layout manually. Now I want to add the accordions inside. I tried with add_rows
and update_field
, but could not do it successfully.
Here is the code attempt:
foreach ($posts as $key => $value) {
$field_key = "field_5cab37b5c28y6"; // flexible_content field key
$value = array(
array( "content" => $value['content'], "acf_fc_layout" => "accordion" ),
array( "title" => $value['title'], "acf_fc_layout" => "accordion" ),
);
update_field( $field_key, $value, $post_id );
}