2013-07-01 108 views

回答

1
Get all posts. See get_posts(array ('numberposts' => -1)) 
For each post get all attachments. See get_children(array ('post_type' => 'attachment', 'numberposts' => -1)) 
For each attachment get the attachment URL. See wp_get_attachment_url() 
If you find the attachment URL in the parent post's content ($post->post_content): 
    If there is another attachment URL with the same file name plus the 1 and 
    both are part of the post content then 
    remove the second image first then 
    use wp_delete_attachment() to delete the physical file. This will remove all meta data and all associations in other posts too. It is the best way to remove attached files (imho). 
+0

謝謝。從上傳新媒體(media-new.php)上傳圖片時是否比上面的代碼有效? –

+0

如何在新媒體中上傳新圖片時如何檢查? –

相關問題