解决了这个问题后,我想更新这个问题。这个问题源于以前版本的WP在上传媒体时没有包含\\u WP\\u attached\\u file meta key,而3.4现在似乎需要这样做。
下面是PHP代码,用于在数据库中循环,验证密钥和图像文件的存在,然后更新数据库。
// descend through the database
$updated = 0;
$skipped = 0;
$error = 0;
$upload_dir = wp_upload_dir();
$sql = sprintf("select * from %s where post_type = \'attachment\'", $wpdb->posts);
$all_attachments = $wpdb->get_results($sql);
foreach ($all_attachments as $attachment) {
// get the meta value
$meta = get_post_meta($attachment->ID, "_wp_attachment_metadata", true);
$file = $meta[\'file\'];
// verify that the file exists
$file_path = $upload_dir[\'basedir\'] . \'/\' . $file;
if (!file_exists($file_path)) {
$error++;
}
else {
// add the meta value, which returns false if it already exists
$adding_meta = add_post_meta($attachment->ID, \'_wp_attached_file\', $file, true);
if ($adding_meta)
$updated++;
else
$skipped++;
}
}
echo \'<div id="message" class="updated"><p>\' . sprintf("%d attachments were updated, %d were skipped and %d had errors.", $updated, $skipped, $error) . \'</p></div>\';