When you upload an image to the WordPress Media Library, it is instantly available for you to use. You can easily insert the image into posts, or into more advanced displays such as a MetaSlider slideshow.
However, behind the scenes, WordPress does a lot of work to make sure this process is simple for you. Your images are uploaded to a folder on your site, and also data about your image is added to your database.
In this guide, I’m going to give an introduction to what happens when you upload an image, with a particular focus on what happens to WordPress media data in your site’s database.
Where are your media files stored?
Your media files are uploaded to the /wp-content/uploads/folder. Normally, the image is also placed inside a folder the month it was uploaded.
I wrote this post in May 2022, so the images in this article are in this folder: /wp-content/uploads/2022/05/.
It is possible to disable this categorization by month if you go to “Settings” then “Media” in your WordPress admin area. Uncheck the box which says, “Organize my uploads into month- and year-based folders”.
Where is data for your media files in the database?
Information about your WordPress images is stored in two database tables:
- wp_posts: This table has one entry for each image. The entry contains the image URL, caption, the upload date, and other key data.
- wp_postmeta: This table contains multiple entries. These entries contain the image’s ALT text and information about different sizes of the image to show on different device sizes.
In the wp_posts table, you’ll find key information for all the media that is uploaded to your site. Your images, PDF files, movies and more will all be recorded here alongside your posts and pages.
The post type for your media files will be “attachment”.
In the image below, I am editing the wp_posts row for one media attachment. You can see the following data:
- ID: The unique number to refer to this image
- post_author: The user who uploaded the image.
- post_date: The date and time that the image was uploaded.
- post_content: The description for the image.
- post_title: The title for the image.
- post_excerpt: The caption for the image.
Further down on this screen, you will see more key information about the image, including the URL of the image.
In the wp_postmeta table, there are multiple separate entries, including for the ALT text and the different sizes of the image.
When you upload an image, WordPress will make multiple copies of the image. The larger copies will be shown on big screens with high resolutions. The smaller copies will be shown on mobile devices and low resolution screens. In the attachment_metadata entry, you will find all the image sizes and also image metadata such as:
- Focal Length
- Shutter Speed
More on image sizes in WordPress
Your original image may end up being stored in more than six different image sizes. In this example below, I uploaded an image using the MetaSlider integration with Unsplash. In the right column, you can see the size in KB of the different image resolutions. The smallest version of the image is only around 5% of the size of the original image.
You have the ability to change these sizes if you go to “Settings” and then “Media” in your WordPress admin area. You can see the size settings in the screenshot below.
4 Replies to “Where is Media Data Stored in the WordPress Database?”
> wp_postmeta: This table has one entry for each image. The entry contains the image URL, caption, the upload date, and other key data.
> wp_posts: This table contains multiple entries. These entries contain the image’s ALT text and information about different sizes of the image to show on different device sizes.
I think you mixed these up. Doesn’t the wp_posts table contain 1 entry per image, and the wp_postmeta contain the alt tag metadata?
Thanks Jonny. You’re right – I’ve fixed the typo.
Thank you for this Post Steve.
Got all the assets from a WP website that got sunk by the infamous PHP version 8 upgrade.
“Not all heroes wear capes” – some meme
That’s great to hear, thanks Nardu