从wordpress媒体库中删除重复的图像

时间:2013-07-01 06:30:43

标签: wordpress

我想知道如何从wordpress媒体库中删除重复的图像,我还想询问媒体上传者如何检查文件的重复。

2 个答案:

答案 0 :(得分: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).

答案 1 :(得分:0)

  

清理上传文件夹中未使用的图片和其他文件。

http://wordpress.org/plugins/upload-janitor/

  

删除未使用的图片

http://wordpress.org/plugins/dnui-delete-not-used-image-wordpress/screenshots/

  

不使用插件时:

go media:   Sort files by Unattached.

delete which is not used.