WordPress Featured Image in database

WordPress Featured Image in database

How featured image stored in MySQL database?

Featured image in wp_posts table:

post_author = '77777'
post_parent = [post_id]
guid = [image url]
post_type = 'attachement'
post_mime_type = 'image/jpeg'

WordPress Featured Image Insider

Featured image in wp_postmeta table:

There are 3 meta_keys hold the image information.

post_id, meta_key, meta_value = [post id], '_thumbnail_id', [featured image post id]
post_id, meta_key, meta_value = [featured image post id], '_wp_attached_file', [image url]
post_id, meta_key, meta_value = [featured image post id], '_wp_attachment_image_alt', [image alt]

WordPress Featured Image Insider

Optimize data structure

Move the featured image record right next to the post.

set @id = 2334; -- post id
set @id1 = 2335; -- new image post id
set @id2= 2339; -- old image post id
update wp_posts set id=@id1 where id=@id2;
update wp_postmeta set post_id=@id1 where post_id=@id2 and meta_key like '_wp_attach%';
update wp_postmeta set meta_value=@id1 where post_id=@id and meta_key='_thumbnail_id';

361 total views, 6 views today

Author: Albert

Leave a Reply