Created
July 9, 2019 09:59
-
-
Save sibysathyanesan/ad83a936b27e7541b08ce0d41a092848 to your computer and use it in GitHub Desktop.
WP featured image in Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Where Featured Images Are Stored | |
The WordPress Genesis theme uses featured images on its posts on several of its themes. If you’re curious as to where the Genesis theme stores the image links on the database, you’ll need to go to a couple of WordPress tables to find them. First and foremost, you’ll need to get the ID of your WordPress post. You can easily find this by hovering over the edit link and checking the ID number. | |
Let’s pretend the post ID is 110. You will then need to find the meta_value in the wp_postmeta table. | |
Table: wp_postmeta | |
meta_id post_id meta_key meta_value | |
544 110 _thumbnail_id 45 | |
SELECT meta_value FROM wp_postmeta WHERE meta_key='_thumbnail_id' and post_id=110; | |
The result is 45. Now that you have the meta_value, you can then search for the link from the wp_posts table. | |
Table: wp_posts | |
ID post_type guid | |
45 attachment http://yourdomain.com/wp-content/uploads/2017/03/featured-image.jpg | |
SELECT guid FROM wp_posts WHERE post_type='attachment' and id=45; | |
The result will be the URL of the image, e.g. http://yourdomain.com/wp-content/uploads/2017/03/featured-image.jpg. | |
It’s an odd place to store the image link, but that’s where it is. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment