如何在Advanced Customs Field PRO中正确保存嵌套转发器

时间:2019-05-30 14:38:57

标签: php wordpress advanced-custom-fields acfpro

我想在嵌套转发器之前显示groupname(textfield)。但是它总是失败。实际上,没有组名也可以。但是,因为它是食物食谱的一种形式,所以我必须继续显示它。

这是我的表单屏幕截图(https://imgur.com/a/guFX98V

和下面的代码


   add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post' );
   function tsm_do_pre_save_post( $post_id ) {
   $allingredients = $_POST['acf']['field_1']; // REPEAT
   foreach ($allingredients as $row)
    {
    $groupname = $row['field_2']; //THIS IS TEXT FIELD GROUP NAME 
    $ingredients_total_unit = $row['field_3']; //   NESTED REPEAT

    // 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
    }

并再次致电

 <ul>' . $groupnameandingredient .'</ul>

但是为什么表单的结果是这样

https://imgur.com/a/iwBPOEw

我只想要以下结果

https://imgur.com/a/7kMr4ZE

0 个答案:

没有答案