邮件特色图像链接存储在WordPress数据库中的哪个位置?

时间:2015-02-21 08:14:40

标签: wordpress

WordPress数据库中存储的精选图片链接在哪里?我在wp_postmeta表格中进行了搜索,但我找不到确切的post_idlinks

这是对的吗?有人可以向我解释它是如何运作的吗?

4 个答案:

答案 0 :(得分:122)

特色图片ID存储在wp_postmeta中,meta_key名为_thumbnail_id。例如:

╔═════════╦═════════╦═══════════════╦═══════════╗
║ meta_id ║ post_id ║ meta_key      ║ meta_value║
╠═════════╬═════════╬═══════════════╬═══════════╣
║ 200     ║ 4       ║ _thumbnail_id ║ 48        ║
╚═════════╩═════════╩═══════════════╩═══════════╝

实际的缩略图链接随后包含在wp_posts中,post_typeattachment。例如:

╔════╦════════════╦═════════════════════════════════════════════════════╗
║ ID ║ post_type  ║ guid                                                ║
╠════╬════════════╬═════════════════════════════════════════════════════╣
║ 48 ║ attachment ║ http://example.com/wp-content/uploads/yourimage.png ║
╚════╩════════════╩═════════════════════════════════════════════════════╝

答案 1 :(得分:11)

我很好奇,所以这里......

  • wp_postmeta表格会为meta_key _thumbnail_id
  • 的帖子保留一个条目
  • meta_value是特色图片的孩子post_id
  • 使用post_id,您可以从wp_postswp_postmeta
  • 获取更多信息

总而言之,如何获取帖子wp_posts的精选图片的子XXX行...

SELECT childpost.* 
FROM wp_posts childpost 
INNER JOIN wp_postmeta parentmeta ON (childpost.ID=parentmeta.meta_value)
WHERE parentmeta.meta_key='_thumbnail_id' 
AND parentmeta.post_id=XXX;

这是同一张图片的元数据

SELECT childmeta.* 
FROM wp_postmeta childmeta 
INNER JOIN wp_postmeta parentmeta ON (childmeta.post_id=parentmeta.meta_value)
WHERE parentmeta.meta_key='_thumbnail_id' 
AND parentmeta.post_id=XXX;

元数据将包含_wp_attached_file相对路径,以及包含一些PHP序列化数据的_wp_attachment_metadata

答案 2 :(得分:10)

这里是我的带有完整网址图片的SQL

SELECT concat((select option_value from wp_options where option_name ='siteurl'  limit 1),'/wp-content/uploads/',childmeta.meta_value)
FROM wp_postmeta childmeta 
INNER JOIN wp_postmeta parentmeta ON (childmeta.post_id=parentmeta.meta_value)
WHERE parentmeta.meta_key='_thumbnail_id' and childmeta.meta_key = '_wp_attached_file'
AND parentmeta.post_id = POST_ID ;

select option_name from wp_options where option_name ='siteurl' 

结果将是这样的

  

http://yourdomain/blog-wp/wp-content/uploads/2015/04/IMG_06062014_155904.png

答案 3 :(得分:7)

即使rnevius的答案似乎正确,结果仍会返回一些具有此类URL的图像: http://www.example.com/?attachment_id=48在我的情况下不起作用。

在Wordpress 4.9.3上进行了测试:

另一种解决方案是改为使用_wp_attached_file

wp_postmeta

_thumbnail_id中搜索值meta_key

meta_id   | post_id   | meta_key            | meta_value
200       | 4         | _thumbnail_id       | 48

wp_postmeta

再次在wp_postmeta中搜索_wp_attached_file中的值meta_key,其中post_id与先前查询中的meta_value匹配

meta_id   | post_id   | meta_key            | meta_value
1020      | 48        | _wp_attached_file   | 2018/09/picture.jpg

查询:

SELECT wp.ID, wpm2.meta_value
FROM wp_posts wp
    INNER JOIN wp_postmeta wpm
        ON (wp.ID = wpm.post_id AND wpm.meta_key = '_thumbnail_id')
    INNER JOIN wp_postmeta wpm2
        ON (wpm.meta_value = wpm2.post_id AND wpm2.meta_key = '_wp_attached_file')