我有一个已有 12 年以上历史的网站,有大约 6000 个帖子和大约 100 个页面,并且使用了大量图像。我的媒体文件夹有几个 GB。我只是想对其进行整理,以便可以从媒体中删除未使用的图像。如何以任何方式简单地获取我的网站中使用的图像列表,无论是在页面中还是在帖子中?
我只是想要一个图像列表,这样我就可以减少服务器上的开销。
我尝试了以下查询,但效果不是很好,因为我想要图像列表,以便我可以仅备份/下载这些图像以及数据库。
SELECT `ID`, `post_title`, `guid` FROM `wp_posts` WHERE `post_content` LIKE '%http://example.com/wp-content/uploads/%'
but it shows only the post's title and ID for the above query.
I want to retrieve the listing in the format such as
https://example.com/wp-content/uploads/2010/01/image1.jpg
https://example.com/wp-content/uploads/2010/02/image2.jpg
https://example.com/wp-content/uploads/2010/01/image3.jpg
etc
您可以使用像 REGEXP_SUBSTR 这样的函数从
post_content
获取 URL
with cte as (
select "This is a test http://exampe.com/wp-content/uploads/somethingElse for a test" as post_content
)
select
REGEXP_SUBSTR(post_content, 'http://[^ ]*') as url,
post_content
from cte;
参见:DBFIDDLE
注意:当 post_content 中出现超过 1 次时,这个简单的示例将无法正常工作!