0

有没有办法从 Sql 中找到没有任何关联图像(内联或附件)的所有帖子?

或者任何人都可以向我解释 wordpress 如何存储图像,因为我不太清楚。我发现它们可以内联在文本中,也可以使用 meta_key = "_wp_attached_file" 存储在 wp_postmeta 中,或者使用 post_type = "attachment" 存储在 wp_posts 中。

这是正确的吗?

任何帮助,将不胜感激。

提前致谢。

4

2 回答 2

1

Wordpress 通过创建附件帖子来管理媒体(图像、文本文档等),以保存有关该媒体的信息及其与其他帖子/帖子的关系(如果有的话)。

要检索没有附加任何图像的所有帖子,您可以执行如下查询:

select * from wp_posts where id not in (select post_id as p from wp_postmeta where meta_key like "_thumbnail_id")
于 2013-10-03T12:20:44.743 回答
1

谢谢,我已经添加:

AND ID not in (select post_id as p from wp_postmeta where meta_key like "_wp_attached_file")

但它仍然返回太多结果。

我已经看到在我的结果的 post_content 中,我有一些图像声明如下:

<img src="/public/Username/filename.jpg">

该查询不排除该帖子。我使用以下方法得到了很好的结果:

SELECT DISTINCT(p.ID), p.post_title, p.post_content FROM `wp_posts` p
LEFT JOIN wp_posts im ON p.ID = im.post_parent AND im.post_type = "attachment" 
WHERE p.post_status ='publish' 
    AND p.post_type = "post" 
    AND im.ID IS NULL
    AND p.post_content NOT REGEXP 'src=".*"' 
于 2013-10-03T12:43:20.063 回答