通过脚本导入Wordpress ACF需要保存Repeater字段

时间:2015-02-19 16:07:56

标签: wordpress advanced-custom-fields

我刚刚制作了一个脚本,用于将JSON Feed导入ACF自定义字段专业版。 当我插入一个只是普通字段的字段时,导入后不需要点击“保存”操作。

update_field('rating', $route['rating'], $post_id);

一切顺利。 但是,当它是一个转发器字段时,我使用此代码:

$startlocation = array();
$startlocation[] = array(
    'lat' => $route['startingSpot']['location']['lat'],
    'lng' => $route['startingSpot']['location']['lng'],
    'description' => $route['startingSpot']['nl'],
    'direction' => $route['startingSpot']['direction']
);
update_field('startlocation', $startlocation, $post_id );

创建导入的帖子后需要点击一下。当我再次运行导入时,字段将被填入。

有没有人知道我是否需要一个不同的脚本,或者给出一个编程点击保存,在脚本创建的帖子之后添加所有自定义字段?

提前致谢, 彼得

1 个答案:

答案 0 :(得分:0)

对于act的转发器字段,您必须使用field_key而不是名称。 这是我的问题的答案。

$startlocation = array();
    $startlocation[] = array(
    'lat' => $route['startingSpot']['location']['lat'],
    'lng' => $route['startingSpot']['location']['lng'],
    'description' => $route['startingSpot']['nl'],
    'direction' => $route['startingSpot']['direction']
);
update_field('field_dhjawhdwkwkhd', $startlocation, $post_id );