【发布时间】:2019-01-07 09:41:35
【问题描述】:
我创建了一个自定义插件来导入和导出 woocommerce 产品。我面临一个问题,当我尝试导入 CSV 时,产品的缩略图被更改并设置为之前添加到产品中的旧缩略图。
我在 CSV 中有完整的图片网址。这是我的导入代码:
$product_img = $row[13]; //Product Image
$res = $wpdb->get_results('select post_id from ' . $wpdb->prefix . 'postmeta where meta_value like "%' . basename($product_img). '%"');
if(count($res) == 0)
{
$res = $wpdb->get_results('select ID as post_id from ' . $wpdb->prefix . 'posts where guid="' . $product_img . '"');
}
$thumbnail_id = $res[0]->post_id;
set_post_thumbnail( $product_id, $thumbnail_id );
$attach_data = wp_generate_attachment_metadata( $thumbnail_id, $product_img );
wp_update_attachment_metadata( $thumbnail_id, $attach_data );
谁能告诉我我错在哪里以及为什么缩略图会用旧的更新。我正在尝试查找过去 1 天的问题,但尚未找到。
提前致谢。
【问题讨论】:
标签: php wordpress woocommerce thumbnails product