Home › Forums › Front-end Issues › Update parent and child repeater programmatically › Reply To: Update parent and child repeater programmatically
Hi John,
I’ve progressed this slightly.
It’s iterating through and adding the column titles to 7 repeater rows. So that works.
The update_sub_repeater is adding data to all 7 child repeater fields but it’s counting up for some reason… it’s adding 2 child repeater rows to the first parent repeater, 3 to the second, 4 to the third and so on.
It’s so close apart from this final part, where am I going wrong?
// Product Code Titles
$contents = $html->find('div[class=product-table]', 0);
$data = array();
$subdata = array();
$rows = $contents->find('tr');
$counter = 0;
$field_key = "field_5ae0882f9d6f9";
$sub_field_key = "field_5ae088999d6fb";
$cellcount = 0;
foreach ($rows as $key_row => $row) {
if($counter == 0) {
foreach ($row->find('td') as $key_cell => $cell) {
$data[] = array(
"column_title" => strip_tags($cell->innertext),
);
}
} elseif($counter >= 1) {
foreach ($row->find('td') as $key_cell => $cell) {
$subdata[] = array(
"text" => strip_tags($cell->innertext),
);
update_sub_field( array($field_key, $cellcount, $sub_field_key), $subdata, $post_id );
$cellcount++;
}
}
$counter++;
}
echo $cellcount;
update_field( $field_key, $data, $post_id );
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.