我有一个API,在其中我通过php将来自门户的模型的图片集引入到Wordpress中的自定义帖子类型中。它会拉入第一张图片,然后像这样手动在Wordpress中上传更多图片。
但是,当我再次获取API时,它将覆盖整个产品组合,而不是对其进行更新!!!
这是代码。
private function set_talent_contents($talent, $post_id)
{
$terms = $talent['www'];
$gender = $talent['gender'];
if($this->actions['full_content'] && $talent['pic_1'] && $talent['pic_1'] != 'http://portal.pha-agency.co.uk/models/' )
{
$attachments = $this->uploadRemoteImageAndAttach($talent['pic_1'], $post_id);
$pictures[] = [ 'image' => $attachments ];
if( $this->actions['feature'] )
{
$output['feature'] = '✓';
set_post_thumbnail( $post_id, $attachments );
}
}else{
$pictures = null;
}
$headshot = (isset($pictures[0]['image']) ? $pictures[0]['image'] : null);
$videos = [];
$polaroids = [];
if($this->actions['full_content'])
{
update_field($this->field_mapping['default']['headshot'], $headshot, $post_id);
update_field($this->field_mapping['default']['portfolio'], $pictures, $post_id);
update_field($this->field_mapping['default']['videos'], $videos, $post_id);
update_field($this->field_mapping['default']['polaroids'], $polaroids, $post_id);
}
update_field($this->field_mapping['default']['header'], $this->field_mapping['default']['header_default'], $post_id);
$talent_cats = array_filter(explode(',', $terms));
if($talent_cats)
{
foreach($talent_cats as $cat)
{
$form_type = '';
// just incase its something like 'Male Model'. we can strip the gender off and try the gender seperatly
$cat = strtolower(trim(str_replace($gender, '', $cat)));
if(isset($this->field_mapping[$cat]))
{
$form_type = $cat;
}elseif(str_contains($cat, 'Sports') ){
$form_type = 'sports';
}elseif(str_contains($cat, 'model') || str_contains($cat, 'kids')){
$form_type = 'models';
}elseif(str_contains($cat, 'actor')){
$form_type = 'casting';
}else{
continue;
}
if($this->actions['full_content'])
{
update_field($this->field_mapping[$form_type]['header'], $this->field_mapping[$form_type]['header_default'], $post_id);
update_field($this->field_mapping[$form_type]['headshot'], $headshot, $post_id);
update_field($this->field_mapping[$form_type]['portfolio'], $pictures, $post_id);
update_field($this->field_mapping[$form_type]['videos'], $videos, $post_id);
update_field($this->field_mapping[$form_type]['polaroids'], $polaroids, $post_id);
}
}
}
现在,我已经继承了此代码,需要使其正常工作。我已经与ACF联系,以查看它是否是转发器字段中的错误,这是响应:
// save a repeater field value
$field_key = "field_12345678";
$value = array(
array(
"sub_field_1" => "Foo",
"sub_field_2" => "Bar"
)
);
update_field( $field_key, $value, $post_id );
现在我不确定如何实现它!