Where is the post featured image link stored in the WordPress database?

前端 未结 4 448
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 06:06

Where is the featured image link stored in the WordPress Database? I searched in the wp_postmeta table but I cannot find out the exact post_id and

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 06:46

    I was curious, so here goes...

    • The wp_postmeta table will hold an entry for the post with meta_key of _thumbnail_id
    • the meta_value is a child post_id for the featured image
    • using that post_id, you can obtain further information from wp_posts and wp_postmeta

    To put it all together, here's how to get the child wp_posts row for the featured image of 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;
    

    And here's the meta data for that same image

    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;
    

    The metadata will include a _wp_attached_file relative path, and a _wp_attachment_metadata containing some PHP serialized data.

提交回复
热议问题