在ACF中通过update_field上传图片
Upload image through update_field in ACF
我正在抓取 XML/RSS 提要以使用高级自定义字段在 Wordpress 中创建帖子。使用 update_field 很容易更新文本和数字字段,但看起来图像是另一回事。我们正在提取的图像 link 是一个简单的 jpg,但是您显然不能将 url 加载到媒体库中。
我研究过使用 wordpress 函数将图像保存到我们的数据库中,然后获取附件 ID 并传递给 ACF。创建此功能需要一些时间,因此我正在寻找处理此功能的潜在其他方法(如果有的话)。
// 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);
还有其他人 运行 遇到这个问题并且有解决方法吗?谢谢
而不是通过 Wordpress 图库上传。我刚刚为图像保存了 url 并在我的模板中使用它。
我正在抓取 XML/RSS 提要以使用高级自定义字段在 Wordpress 中创建帖子。使用 update_field 很容易更新文本和数字字段,但看起来图像是另一回事。我们正在提取的图像 link 是一个简单的 jpg,但是您显然不能将 url 加载到媒体库中。
我研究过使用 wordpress 函数将图像保存到我们的数据库中,然后获取附件 ID 并传递给 ACF。创建此功能需要一些时间,因此我正在寻找处理此功能的潜在其他方法(如果有的话)。
// 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);
还有其他人 运行 遇到这个问题并且有解决方法吗?谢谢
而不是通过 Wordpress 图库上传。我刚刚为图像保存了 url 并在我的模板中使用它。