2015-09-08 44 views
0

我有18,000多個wordpress帖子,我使用的是一個函數來隱藏帖子中的第一張圖片,但我不想再這麼做。我只想使用精選圖片,就是這樣,而不必在帖子中插入精選圖片來隱藏它(使用該功能)。手動刪除wordpress數據庫中的第一張圖片

我在考慮只是手動刪除文本編輯器中的所有內容,但不知道要刪除哪一個,因爲它存在2或3次。例如:

INSERT INTO `wp_posts` VALUES(16179, 88, '2009-05-28 08:32:47', '2009-05-28 12:32:47', '<img src="http://localhost/readjunk/wp-content/uploads/2009/05/news_0509_takingbacksundayalbum.jpg" alt="news_0509_takingbacksundayalbum" title="news_0509_takingbacksundayalbum" width="450" height="250" class="alignnone size-full wp-image-16180" />\r\nTaking Back Sunday will be streaming New Again in its entirety on their <a href="http://www.myspace.com/takingbacksunday">MySpace page</a> on Thursday May 28th and Friday May 29th. New Again officially hits stores next Tuesday, June 2nd.\r\n<!--more-->\r\n\r\nTaking Back Sunday will <a href="http://localhost/readjunk/news/music/blink-182-reunite-and-announce-summer-tour/">be touring on select dates</a> with Blink 182. Check out their music video for Sink Into Me <a href="http://localhost/readjunk/media/music-video-taking-back-sunday-sink-into-me/">here</a>.\r\n\r\nFor more info visit: <a href="http://www.takingbacksunday.com">www.takingbacksunday.com</a>\r\n', 'MySpace hosting Taking Back Sunday "New Again" listening party tonight and Friday', 0, '', 'publish', 'open', 'open', '', 'myspace-hosting-taking-back-sunday-new-again-listening-party-tonight-and-friday', '', '', '2009-05-28 08:32:47', '2009-05-28 12:32:47', '', 0, 'http://localhost/readjunk/?p=16179', 0, 'post', '', 0, NULL); 
INSERT INTO `wp_posts` VALUES(16180, 88, '2009-05-28 08:28:27', '2009-05-28 12:28:27', '', 'news_0509_takingbacksundayalbum', 0, '', 'inherit', 'open', 'open', '', 'news_0509_takingbacksundayalbum', '', '', '2009-05-28 08:28:27', '2009-05-28 12:28:27', '', 16179, 'http://localhost/readjunk/wp-content/uploads/2009/05/news_0509_takingbacksundayalbum.jpg', 0, 'attachment', 'image/jpeg', 0, NULL); 
INSERT INTO `wp_posts` VALUES(16181, 88, '2009-05-28 08:32:36', '2009-05-28 12:32:36', '<img src="http://localhost/readjunk/wp-content/uploads/2009/05/news_0509_takingbacksundayalbum.jpg" alt="news_0509_takingbacksundayalbum" title="news_0509_takingbacksundayalbum" width="450" height="250" class="alignnone size-full wp-image-16180" />\nTaking Back Sunday will be streaming New Again in its entirety on their <a href="http://www.myspace.com/takingbacksunday">MySpace page</a> on Thursday May 28th and Friday May 29th. New Again officially hits stores next Tuesday, June 2nd.\n<!--more-->\n\nTaking Back Sunday will <a href="http://localhost/readjunk/news/music/blink-182-reunite-and-announce-summer-tour/">be touring on select dates</a> with Blink 182. Check out their music video for Sink Into Me <a href="http://localhost/readjunk/media/music-video-taking-back-sunday-sink-into-me/">here</a>.\n\nFor more info visit: <a href="http://www.takingbacksunday.com">www.takingbacksunday.com</a>\n', 'MySpace hosting Taking Back Sunday "New Again" listening party tonight and Friday', 0, '', 'inherit', 'open', 'open', '', '16179-revision', '', '', '2009-05-28 08:32:36', '2009-05-28 12:32:36', '', 16179, 'http://localhost/readjunk/uncategorized/16179-revision/', 0, 'revision', '', 0, NULL); 

它只是img標籤或只是第一行?

+0

很好的IDS樣子16179以上。你問如何手動做一個基於ID的刪除?有沒有其他的表格會這樣做會禁止它或把它們擰緊? – Drew

+0

耶不知道。我在wp_posts,所以不知道爲什麼有2或3在那裏相同的職位。我正在使用一個精選的圖像插件,使用後第一個圖像,所以也許這就是創建一個額外的ID?不是程序員那麼不確定。我想刪除一個帖子中的圖像,所以不知道我是否應該嘗試刪除第二個,因爲第一個可能是附件? –

+0

第一個是帖子,第二個是附件,第三個是修改版。你可以在插入參數中看到'post_type',它是最後一個參數「post」,「attachment」,「revision」的第4個參數。您不需要觸摸附件或修訂版,可能會刪除所有修訂版。 – totels

回答

0

在你的問題你發佈3條不同的INSERT語句表示初始後(用一個post_status「發佈」),下一行是上傳到媒體庫(與attachment一個post_type)的圖像和第三代表編輯的初始帖子(與post_status的「繼承」)

而不是使用文本編輯器,我會建議這樣做以編程方式。您可以遍歷所有帖子並使用WordPress API創建新的編輯,或者您可以使用新的post_content更新最新帖子。

您應該可以使用正則表達式來刪除內容中的第一個圖像。喜歡的東西:

$post->post_content = preg_replace("~^[^>]*>~", "", $post->content); 

退房的正則表達式描述在Regex101.com:https://regex101.com/r/jP9vZ6/1

+0

謝謝,我該如何去使用它?放在function.php? –

+0

你可以在functions.php中做到這一點,或者你可以使用開發/調試欄/調試欄控制檯插件從瀏覽器運行任意PHP。安裝完成後,點擊右上角的調試,然後點擊左側的控制檯。絕對在非生產服務器上做到這一點:) – doublesharp