【发布时间】:2016-01-09 01:50:11
【问题描述】:
我有以下问题:我为我想要存储数百张图像的自定义帖子类型创建了一个带有 acf 的图像字段。
- 我用 wordpress 导入这些图片。
- 我使用“非常简单的 csv 导入器”运行导入以创建大量帖子并将我在 1. 步骤中上传的图像分配给 acf 图像字段。
我已经尝试了很多 update_field() 和 get_field_object() 函数,但没有任何效果。 update_field() 函数的文档很遗憾很不完整,我必须如何使用这个函数来更新图像字段?
这是我正在使用的代码:
function really_simple_csv_importer_save_meta_filter( $meta, $post, $is_update ) {
$attachment_url = $meta['field_55f2be2a39177'];
$image_id = pn_get_attachment_id_from_url( $attachment_url ); // function to retrieve the image id that i need for the update_field()
$field_key = "field_55f2be2a39177";
update_field($field_key, $image_id);
return $meta;
}
add_filter( 'really_simple_csv_importer_save_meta', 'really_simple_csv_importer_save_meta_filter', 10, 3 );
【问题讨论】:
-
向我们展示您尝试过的代码以及您失败的地方
-
function really_simple_csv_importer_save_meta_filter( $meta, $post, $is_update ) { $attachment_url = $meta['field_55f2be2a39177']; $image_id = pn_get_attachment_id_from_url( $attachment_url ); // function to retrieve the image id that i need for the update_field() $field_key = "field_55f2be2a39177"; update_field($field_key, $image_id); return $meta;} add_filter( 'really_simple_csv_importer_save_meta', 'really_simple_csv_importer_save_meta_filter', 10, 3 );
标签: image field advanced-custom-fields