gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:54:06 27 4
gpt4 key购买 nike

我想知道如何从 WordPress 媒体库中删除重复的图像,我还想问媒体 uploader 如何检查文件的重复项。

最佳答案

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).

关于wordpress - 从 WordPress 媒体库中删除重复的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17398577/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com