800,000+ WordPress sites are already using MetaSlider!

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.


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

The post type for your media files will be “attachment”.

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

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.

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

6 Replies to “Where is Media Data Stored in the WordPress Database?”

  1. Jonny
    November 17, 2022

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

    1. Steve Burge
      December 27, 2022

      Thanks Jonny. You’re right – I’ve fixed the typo.

  2. February 2, 2023

    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

    1. Steve Burge
      February 2, 2023

      That’s great to hear, thanks Nardu

  3. Bill Duncan
    February 15, 2024

    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. Steve Burge
      February 15, 2024

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

Leave a Comment

Start Using Your Slider Today!

Create and publish WordPress slideshows in minutes… What are you waiting for?