http://vectorian.com

05/Oct/2011更新: 新版本3.2.0.2已修正這個問題,Quote內的可以不理。
其實用Add From Server匯入後,還會有一些問題。
假如你跟我一樣,圖片都沒有用"/年/月/"去分開,使用Add From Server匯入後,圖片雖然存放的位置不變,但WP Database中記錄的media absolute url就會含有"/年/月/"路徑。
所有你要運行以下SQL去修正連結。
執行前,小心把錯誤的圖片連結更改(如2011/06),做這個UPDATE之前,最好確認一個該月份是否真的存在圖片,以下面SQL為例,把含有2011/06的去掉,替換至實際的資料夾。
UPDATE wp_posts SET guid = replace(guid, '/wp-content/uploads/images/2011/06/' , '/wp-content/uploads/images/');
<?php require_once ('wp-config.php'); require_once ('wp-admin/includes/admin.php'); require_once ('wp-includes/functions.php'); $server = DB_HOST; $username = DB_USER; $password = DB_PASSWORD; $dbname = DB_NAME; $url = get_bloginfo('url'); mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); //find out all attachment records which is no parent post. $sql = "SELECT ID, guid FROM `wp_posts` WHERE `post_type` = 'attachment' AND post_parent=0"; $attachment_post = mysql_query($sql); while ($rows = mysql_fetch_assoc($attachment_post)) { //$guid is the relative or absolute URL of images. $guid = str_replace($url, '', $rows['guid']); //find the first post , where post content contain the $guid (image url). //Due to WordPress's limitation, one media only can recognize to one post/page's ID. //If more than one Post/Page has use the media, WordPress will retain the first ID to media. $sql = "SELECT ID FROM `wp_posts` WHERE post_content LIKE '%" . mysql_real_escape_string($guid) . "%' AND post_type in ('post','page','template') ORDER BY `post_date` desc,`post_modified` desc LIMIT 1"; $match_post = mysql_fetch_assoc(mysql_query($sql)); //Update the attachment's post_parent to related post/page ID. $sql = "UPDATE `wp_posts` SET post_parent='" . $match_post['ID'] . "' WHERE ID=" . $rows['ID'] . " LIMIT 1"; mysql_query($sql); } echo 'Done!'; mysql_close(); ?>