douwei2966
2014-09-17 20:22
浏览 57
已采纳

通过update_field无人值守地将行添加到ACF的Repeater

I'm using acf with reapeters. I'm trying to add a row to a repeater through update_field, however, when I open a post to confirm if it works in wordpress' admin, it kept loading and gave me this error:

Fatal error: Maximum execution time of 30 seconds exceeded.

When I echo $value, I get this: "bool(false)", here's my code:

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();
    }
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • doumi9661 2015-05-29 10:20
    最佳回答

    the problem is that the field key you are using is not the correct one. you need to go to custom fields menu and from the top screen options show the field key ids. then copy the field key Id of the repeater and use it in the update_field method. is you use field name you will get an infinite loop and a fatal error due to memory leakage.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题