Where is Media Data Stored in the WordPress Database?

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. Our team wrote a similar guide for finding taxonomy and term data.


WordPress media files vs data

When you upload an image to WordPress, two things happen: the physical file is stored in your uploads directory, and information about that file is stored in your database. Understanding this distinction makes it much easier to troubleshoot media-related issues.


Why understanding media storage matters

Knowing where WordPress stores media can help when:

  • Migrating a website.
  • Troubleshooting missing images.
  • Reducing storage usage.
  • Optimizing image performance.
  • Repairing broken media links.
  • Cleaning up unused uploads.

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”.

Upload settings for WordPress media files

Where is data for your media files?

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. Click here to see what files types WordPress allows.

The post type for your media files will be “attachment”. WordPress treats uploaded media as a special type of content called an attachment. Attachments are stored alongside posts and pages in the database, but they use a different post type designed specifically for media files.

WordPress Media File Settings in Database rows

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.
WordPress Media File options in a Database table

Further down on this screen, you will see more key information about the image, including the URL of the image.

WordPress Media File Settings in a Database entry

In the wp_postmeta table, there are multiple separate entries, including for the ALT text and the different sizes of the image.

WordPress Media File Settings in a Database table

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:

  • Aperture
  • Credit
  • Camera
  • Copyright
  • Focal Length
  • Shutter Speed
  • Orientation
WordPress Media File Settings in the Database

What about featured images?

WordPress stores featured image relationships in the wp_postmeta table. The featured image itself remains an attachment, while a separate database entry connects the image to a post or page.

What about ALT text?


WordPress stores ALT text separately from image captions and descriptions. This information is saved in the wp_postmeta table and helps improve both accessibility and image SEO.


More on image sizes in WordPress

Your original image may end up being stored in more than six different image sizes.

WordPress automatically generates multiple versions of uploaded images so it can serve appropriately sized files to different devices. Smaller images load faster on mobile devices, while larger versions are available for high-resolution displays.

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.

Image files sizes in WordPress

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.

WordPress Media File Settings

How MetaSlider Uses Media Library Images

MetaSlider works directly with the native WordPress Media Library. When you add an image to a slideshow, MetaSlider uses the attachment information already stored by WordPress rather than creating duplicate copies of the image. MetaSlider itself relies on WordPress database tables rather than creating a separate media storage system.


More on MetaSlider and Media Storage

Understanding how WordPress stores media files can make it much easier to manage your website, troubleshoot image issues, and optimize performance. Every uploaded image exists in two places: the physical file stored in your uploads directory and the attachment data stored in your WordPress database. Together, these systems allow WordPress to generate image sizes, manage metadata, and make media files available throughout your site.

If you’d like to learn more about working with images and media in WordPress, explore our guides on creating an image and text carousel, building a carousel slideshow, using captions in MetaSlider, optimizing WordPress images for sliders and galleries, and understanding how MetaSlider stores slideshow information in the database. These resources will help you build faster, more organized, and more visually engaging WordPress websites.

Get the best WordPress slideshow plugin

8 Comments

  1. > 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?

  2. 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

  3. Maybe a related question.

    I thousands of more photos in my Uploads folder than used on my site. Deleted all from Media Library to start over but cannot remove any photos from Uploads. Used FTP and they all reappear. Changed permissions to 777, delete and all reappear, deleted through hosting fire manager – all reappear. I need to delete these 10,,0 media files to clean the site and so far I can find no answer. Any ideas?

    Thanks,
    Bill

    1. Hi Bill. This may be caused by server permissions so this could be unique to your site. However are some good plugins to clean your library including “Media Cleaner”.

  4. Hi

    Thanks for the article.
    I see “_wp_attachment_backup_sizes” in your meta, but can’t find it on a page I checked. Is that a special plugin that creates that?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *