Home › Forums › Add-ons › Flexible Content Field › Help copy nested ACF Flexible Content row from one page to another
I have two pages that are location for the same flexible content group. The group consists of a flexible content field that contains a repeater which contains another flexible content. And I want to copy a row from this last nested flexible content, to the corresponding flexible content in the other page.
This is the code I have so far, but is not working.
With this function I get the fields structure:
function kb_update_elements_target($post_id, $flexibleContent) {
$rows = array();
if (have_rows($flexibleContent, $post_id)) {
while (have_rows($flexibleContent, $post_id)) {
$rows[] = the_row();
if ( get_row_layout() == 'layout_hero' ) {
if (have_rows('hero_row', $post_id)) {
while ( have_rows( 'hero_row', $post_id ) ) {
the_row();
if ( have_rows( 'hero_elements', $post_id ) ) {
while ( have_rows( 'hero_elements', $post_id ) ) {
the_row();
if ( get_row_layout() == 'heading_element' ) {
get_sub_field( 'heading', $post_id );
}
}
}
}
}
}
}
}
return $rows;
}
Then another function that is called through ajax get this data and updates the target page flexible content field:
$templateSection = kb_update_elements_target($sectionTemplateID, 'flexible_sections');
$pageContent = kb_update_elements_target($currentPageID, 'flexible_sections');
array_splice( $pageContent, 0, 0, $templateSection );
update_field( 'flexible_sections', $pageContent, $currentPageID );
But is not working, I can’t add the nested flexible content row in the Template into the corresponding field on the target page. Could someone point me in the right direction?
Thank you.
Jorge
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.