WordPress数据库中存储的精选图片链接在哪里?我在wp_postmeta
桌子上搜索但我找不到确切的post_id
和links
.
它是否正确?有谁能请向我解释它是如何工作的?
特色图像ID wp_postmeta
与meta_key
被调用者一起存储_thumbnail_id
.例:
????????????????????????????????????????????????? ? meta_id ? post_id ? meta_key ? meta_value? ????????????????????????????????????????????????? ? 200 ? 4 ? _thumbnail_id ? 48 ? ?????????????????????????????????????????????????
然后,实际的缩略图链接包含在wp_posts
a 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
帖子的特色图像的子行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/?attach_ment = 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')