答案 0 :(得分:0)
最后我得到了答案。
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
$attach_id = wp_insert_attachment( $attachment, $file_path, '' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
wp_update_attachment_metadata( $attach_id, $attach_data );
$imageid = set_post_thumbnail( $post_id, $attach_id );
add_post_meta($post_id , '_thumbnail_id', $attach_id);
答案 1 :(得分:0)
检查WordPress文件权限