2013-10-03 41 views
0

是否有任何方法可以从Sql中找到没有任何关联图像(内联或附件)的所有帖子?WordPress的 - 获取所有文章没有图像?

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

这是正确的吗?

任何帮助,将不胜感激。

在此先感谢。

+0

帖子作为一个对象返回。该对象内是特色图像ID,因为图像也存储为自己的帖子。只需返回对象键减去特色图像之一。 – ggdx

回答

1

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

要检索的所有帖子不附加您可以执行这样的查询任何图像:

select * from wp_posts where id not in (select post_id as p from wp_postmeta where meta_key like "_thumbnail_id") 
+0

谢谢,我补充说: – teone

0

谢谢,我说:

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"> 

而且该查询doen't exlude该职位。我得到了一个很好的结果使用:

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=".*"' 
相关问题