Php 通过ACF中的更新_字段上载图像
我正在抓取一个XML/RSS提要,以便使用高级自定义字段在Wordpress中创建帖子。使用update_字段很容易更新文本和数字字段,但看起来图像是另一回事。我们正在提取的图像链接是一个简单的jpg,但您显然无法将url加载到媒体库中 我已经研究过使用wordpress函数将图像保存到我们的数据库中,然后获取附件id并传递给ACF。这个函数将需要一点时间来创建,所以我正在寻找其他可能的处理方法(如果有的话)Php 通过ACF中的更新_字段上载图像,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我正在抓取一个XML/RSS提要,以便使用高级自定义字段在Wordpress中创建帖子。使用update_字段很容易更新文本和数字字段,但看起来图像是另一回事。我们正在提取的图像链接是一个简单的jpg,但您显然无法将url加载到媒体库中 我已经研究过使用wordpress函数将图像保存到我们的数据库中,然后获取附件id并传递给ACF。这个函数将需要一点时间来创建,所以我正在寻找其他可能的处理方法(如果有的话) 还有谁遇到这个问题并有办法解决吗?谢谢你,而不是通过Wordpress多媒体资料上传。
还有谁遇到这个问题并有办法解决吗?谢谢你,而不是通过Wordpress多媒体资料上传。我只是保存了图像的url并在模板中使用了它。而不是通过Wordpress gallery上传。最后,我保存了图像的url并在模板中使用它
// create new post
$new_post = array(
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'media'
);
$post_id = wp_insert_post($new_post);
wp_set_object_terms($post_id, $media_type, 'taxonomy_media');
// use ACF API to update fields in post
// update_field( $field key, $value, $post_id)
update_field('field_xxxxxxxxxx', $title, $post_id);
update_field('field_xxxxxxxxxx', $url, $post_id);
update_field('field_xxxxxxxxxx', $image, $post_id); // wont work
update_field('field_xxxxxxxxxx', $name, $post_id);