php - ACF 转发器字段覆盖而不是更新
问题描述
我有一个 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 );
现在我只是不确定如何实现它!
解决方案
推荐阅读
- java - 如何制作连续添加按钮
- javascript - 使用 Axios 请求 API - 未经授权
- java - Java 15:使用嵌入的 tomcat10 制作 jaxws 的 Maven 项目
- matlab - 为什么在计算滤波器(系统)的脉冲响应时,最后会出现“尾巴”
- python - jupyter 中的 loc 函数不适用于过滤我的数据框
- python - 如何在Python中为稀疏矩阵在整个对角线上放置一个条目
- spring-boot - 带有日期的对象数组的 Elasticsearch 查询
- wordpress - 有没有办法将数据从 WP Formidable Forms 中的转发器字段传输到 ActiveCampaign?
- python - 如果另一个 Python pandas 数据框中的两个日期之间的日期,则更新列
- mysql - 无法通过 Workbench(或任何 gui)连接到数字海洋 LEMP 堆栈 MySql,但可以通过终端 mysql cmd 连接