【问题标题】:Wordpress not creating image thumbnailWordpress 不创建图像缩略图
【发布时间】:2015-08-19 00:42:02
【问题描述】:

我在前端有一个自定义上传功能,用于自定义帖子类型。如果我在后端编辑帖子,则特色图片显示为附件,但在媒体库中它只是一个默认占位符。我的图像代码有问题吗?好像它不是'生成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 ); 

【问题讨论】:

  • 仍然没有任何运气。任何人都可以提供见解吗?

标签: wordpress


【解决方案1】:

想通了。

wp_update_attachment_metadata($post_id, $values);

应该是

wp_update_attachment_metadata($attach_id, $values);

愚蠢的错别字。

【讨论】:

    猜你喜欢
    • 2014-11-25
    • 2014-07-23
    • 2011-02-08
    • 2012-09-21
    • 2018-10-31
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多