
Hi, i want to display Ingredient-Group-Name(textfield) before the nested repeater. But it always fails. Actually, without it this form is fine. But because it’s a form for food recipes so I have to keep showing it.
this my functions.php
add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post' );
function tsm_do_pre_save_post( $post_id ) {
$allingredients = $_POST['acf']['field_1']; // REPEATER
foreach ($allingredients as $row)
{
$groupname = $row['field_2']; //THIS IS TEXT FIELD Ingredient-Group-Name
$ingredients_total_unit = $row['field_3']; // NESTED REPEATER
// loop through repeater rows
if( $ingredients_total_unit )
{
foreach($ingredients_total_unit as $sub_row)
{
// add extra data to row
$unit = $sub_row['field_3A'];
$total = $sub_row['field_3B'];
$ingredients = $sub_row['field_3C'];
$ingredientsall .= '<li>' . $ingredients . ' ' . $total . ' ' . $unit . '</li>';
}
}
$groupnameandingredient .= '<p>' . $groupname . '</p>' . $ingredientsall . ''; // THIS IS WRONG PART
}
and called again with
<ul>' . $groupnameandingredient .'</ul>
But my post result is
Ingredient-Group-Name AAA
— 111
— 222
Ingredient-Group-Name BBB
— 111
— 222
— 333
— 444
Ingredient-Group-Name CCC
— 111
— 222
— 333
— 444
— 555
— 666
I just want the results as below
Ingredient-Group-Name AAA
— 111
— 222
Ingredient-Group-Name BBB
— 333
— 444
Ingredient-Group-Name CCC
— 555
— 666
Thanks a lot