WordPress数据库中存储的特色图片链接在哪里?我在wp_postmeta
表格中搜索,但找不到确切的post_id
和links
。
这个对吗?谁能告诉我它是如何工作的?
Answers:
该功能的图像ID存储在wp_postmeta
一个meta_key
叫_thumbnail_id
。例:
╔═════════╦═════════╦═══════════════╦═══════════╗
║ meta_id ║ post_id ║ meta_key ║ meta_value║
╠═════════╬═════════╬═══════════════╬═══════════╣
║ 200 ║ 4 ║ _thumbnail_id ║ 48 ║
╚═════════╩═════════╩═══════════════╩═══════════╝
实际缩略图的链接,然后包含在wp_posts
用post_type
的attachment
。例:
╔════╦════════════╦═════════════════════════════════════════════════════╗
║ ID ║ post_type ║ guid ║
╠════╬════════════╬═════════════════════════════════════════════════════╣
║ 48 ║ attachment ║ http://example.com/wp-content/uploads/yourimage.png ║
╚════╩════════════╩═════════════════════════════════════════════════════╝
我很好奇,所以这里...
wp_postmeta
表将举行与后一个条目meta_key
的_thumbnail_id
meta_value
是post_id
精选图片的孩子post_id
,您可以从wp_posts
和获取更多信息wp_postmeta
综上所述,这是如何获取子wp_posts
行以显示post的特色图片的方法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
相对路径,并_wp_attachment_metadata
包含一个包含一些PHP序列化数据的数据。
这里我的SQL与完整的URL图像
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
即使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')
post_id
图像和图像?