【问题标题】:Adding rows to a ACF's Repeater through update_field working unappropiately通过 update_field 将行添加到 ACF 中继器工作不正常
【发布时间】:2014-11-12 00:40:57
【问题描述】:

我正在使用带有中继器的 acf。 我正在尝试通过 update_field 向转发器添加一行,但是,当我打开一个帖子以确认它是否在 wordpress 的管理员中工作时,它一直在加载并给我这个错误:

Fatal error: Maximum execution time of 30 seconds exceeded.

当我回显 $value 时,我得到:“bool(false)”,这是我的代码:

foreach($dishes as $current_dish)
{
    $local_category_id = strval($current_dish['id_CategoriaTicket']);

    if($local_category_id == $categoryId)
    {
        $prueba = $current_category->post_title;

        $new_dish = array(
            'post_title' => $current_dish['Descripcion'],
            'post_status'   => 'publish',
            //'post_content' =>'',
            'post_type' => 'products'
            //'post_author' => $user->ID
        );

        $post_id = wp_insert_post( $new_dish );

        global $cpt_onomy;
        $cpt_onomy->wp_set_post_terms( $post_id , $prueba, 'categories');

        update_post_meta($post_id, 'product_type', "Platillo");

        $field_key = 'product1';

        $value = get_field($field_key, $post_id);

        $value[] = array("price_id" => "2",
            "price" => "30",
            "location" => 2
            );


        update_field($field_key, $value, $post_id );
        exit();
    }
}

【问题讨论】:

    标签: php wordpress repeater advanced-custom-fields


    【解决方案1】:

    问题是您使用的字段键不是正确的。 您需要转到自定义字段菜单,然后从顶部屏幕选项显示字段键 ID。 然后复制转发器的字段键 ID 并在 update_field 方法中使用它。 如果你使用字段名,你会因为内存泄漏而出现无限循环和致命错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-03
      • 2017-10-03
      • 1970-01-01
      • 2018-04-17
      • 2015-03-30
      • 2018-04-02
      • 1970-01-01
      • 2019-01-07
      相关资源
      最近更新 更多