Wordpress没有创建图像缩略图

时间:2015-08-19 00:42:03

标签: wordpress

我在前端有一个自定义上传功能,用于自定义帖子类型。如果我在后端编辑帖子,则特色图像显示为附加但在媒体库中它只是一个默认占位符。我的图片代码有问题吗?这就像它不是'生成wordpress缩略图

$uploaddir = wp_upload_dir();
$file = $placeholder;
$uploadfile_pl = $uploaddir['path'] . '/' . basename( $file['name'] );

move_uploaded_file( $file['tmp_name'] , $uploadfile_pl );
$filename = basename( $uploadfile_pl );

$wp_filetype = wp_check_filetype(basename($filename), null );

$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
    'post_content' => '',
    'post_status' => 'inherit',
    'menu_order' => 1000
);
$attach_id = wp_insert_attachment( $attachment, $uploadfile_pl, $post_id);
require_once( ABSPATH . 'wp-admin/includes/image.php' );

$values = wp_generate_attachment_metadata($attach_id, $uploadfile_pl);
wp_update_attachment_metadata($post_id, $values);

set_post_thumbnail( $post_id, $attach_id ); 

1 个答案:

答案 0 :(得分:1)

想出来。

wp_update_attachment_metadata($post_id, $values);

应该是

wp_update_attachment_metadata($attach_id, $values);

愚蠢的错别字。