admin管理员组文章数量:1395744
I'm trying to get the file locations of all featured images used in draft type posts via SQL and phpmyadmin.
posts type attachment should hold the location of the image in the guid column.
SELECT voybp_posts.guid
FROM voybp_posts
WHERE voybp_posts.ID IN (
SELECT voybp_postmeta.meta_value
FROM voybp_postmeta
WHERE voybp_postmeta.post_id IN (
SELECT voybp_posts.ID
FROM voybp_posts
WHERE voybp_posts.post_status="draft"))
This script should be good but its very complex and takes forever to execute, any way for me to simpplify it?
I'm trying to get the file locations of all featured images used in draft type posts via SQL and phpmyadmin.
posts type attachment should hold the location of the image in the guid column.
SELECT voybp_posts.guid
FROM voybp_posts
WHERE voybp_posts.ID IN (
SELECT voybp_postmeta.meta_value
FROM voybp_postmeta
WHERE voybp_postmeta.post_id IN (
SELECT voybp_posts.ID
FROM voybp_posts
WHERE voybp_posts.post_status="draft"))
This script should be good but its very complex and takes forever to execute, any way for me to simpplify it?
Share Improve this question edited Mar 28, 2020 at 14:51 Adilicious asked Mar 28, 2020 at 13:49 AdiliciousAdilicious 1193 bronze badges1 Answer
Reset to default 0Alright this worked for me:
First run the bellow script to generate the file locations of all files used for draft posts.
SELECT voybp_posts.guid
FROM voybp_posts
WHERE voybp_posts.ID IN (SELECT voybp_postmeta.meta_value
FROM voybp_postmeta
WHERE voybp_postmeta.post_id IN (
SELECT voybp_posts.ID
FROM voybp_posts
WHERE voybp_posts.post_status="draft")
AND voybp_postmeta.meta_key="_thumbnail_id")
Export this as a CSV file and save it to desktop, then using notepad++ or a similar program use find/replace to add rm to the beginning of every line.
Next SSH into your server and execute the rm commands.
Next you modify the above script and run it to delete the attachment files in the database that lead to nothing.
DELETE
FROM voybp_posts
WHERE voybp_posts.ID IN (SELECT voybp_postmeta.meta_value
FROM voybp_postmeta
WHERE voybp_postmeta.post_id IN (
SELECT voybp_posts.ID
FROM voybp_posts
WHERE voybp_posts.post_status="draft")
AND voybp_postmeta.meta_key="_thumbnail_id")
Finally we find and delete the draft posts.
DELETE
FROM voybp_posts
WHERE voybp_posts.post_status="draft"
AND voybp_posts.post_type="post"
Hope this helps
本文标签: mysqlFind locations of all featured images of draft posts via SQL
版权声明:本文标题:mysql - Find locations of all featured images of draft posts via SQL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744623704a2616185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论