0
你好朋友,我曾經設置發佈縮略圖programetically。Wordpress wp_update_attachment_metadata圖片寬度和高度= 1?
這是我的代碼。
foreach ($csv as $key => $value) {
$filename = "wp-content/uploads/images/".$value[8].".jpg";
$wp_filetype = wp_check_filetype(basename($filename), null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => 'this is the first project file.',
'post_status' => 'Published'
);
$my_post = array(
'post_title' => $value[0],
'post_content' => $value[2],
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'post_staff'
);
$post_id = wp_insert_post($my_post);
$attach_id = wp_insert_attachment($attachment, $filename,$post_id);
$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
wp_update_attachment_metadata($attach_id, $attach_data);
add_post_meta($post_id, '_thumbnail_id', $attach_id);
update_post_meta($post_id, '_staff_name', $value[1]);
update_post_meta($post_id, '_staff_city', $value[3]);
update_post_meta($post_id, '_staff_postal_code', $value[4]);
update_post_meta($post_id, '_staff_direct_line', $value[5]);
update_post_meta($post_id, '_staff_fax', $value[6]);
update_post_meta($post_id, '_staff_email', $value[7]);
$tagd = array(9);
wp_set_post_terms($post_id, $tagd, 'department');
if($value[3] == "St. John's, NL"){
$tagl = array(8);
}else if($value[3] == "Corner Brook"){
$tagl = array(7);
}
wp_set_post_terms($post_id, $tagl, 'location');
if(set_post_thumbnail($post_id, $attach_id)){
echo "image set";
}
}
這是工作正常,但與大小1×1 WIDTH = 1和高度的進口特徵圖像= 1
爲什麼需要寬度和高度爲1 autometically請幫助。
當我試圖使用get_the_post_thumbnail
獲取圖像的返回圖像。
找到圖像,但默認情況下圖像寬度= 1,高度= 1。
這是我的代碼。
get_the_post_thumbnail(get_the_ID(), array(250,165))
謝謝。
嗨,我現在遇到這個問題,你有沒有找到解決辦法? – brndnmg
@brndnmg請檢查我的答案我把答案放在我的問題上。此功能正常工作。 –