How to Delete All WordPress Media

If we have previously deleted unused media in WordPress, what if we want to delete all WordPress media?

Some of you might have previously thought that deleting media from WordPress is as simple as deleting the wp-content/uploads folder.

However, if we only delete the wp-content/uploads folder, our media page will still display the previous list of media and it will not be usable at all.

The solution? We will certainly discuss how to delete all WordPress media here so that the media is truly removed from the hosting and also removed from the WordPress media page.

How to Delete All WordPress Media

WARNING: This method will delete all media in WordPress and cannot be undone if you do not have a backup. Please perform a backup so that the website can be restored if there is any deletion error later.

For this method, we can go through the WordPress dashboard as an easy way, or we can also do it manually using the database. If you want to use the manual method, make sure that you have obtained or know the name of the database used in your WordPress installation.

However, if we go through the WordPress dashboard, we can delete it directly without using additional plugins and certainly without having to find out the database name.

Option 1: Deleting All WordPress Media via the Dashboard

This is the easiest way to delete all WordPress media, because we do not need to find out our database name and can directly open the WordPress dashboard page as an admin.

After being on the admin dashboard page, we can open the Media → Library page to start deleting all media that has been uploaded to our WordPress.

Cara Menghapus Semua Media WordPress - 1-1

On the media page, make sure to change the media view to list view, then change the number of media displayed to be higher by opening the Screen Options

Cara Menghapus Semua Media WordPress - 1-2

option. Change the Number of items per page to adjust how many media items are displayed on one page. By default, the number of media displayed is 20.

However, because we are going to delete all media here, we can fill it with a larger number, for example 500, so that the deletion process can be faster.

Cara Menghapus Semua Media WordPress - 1-3

If we want to delete media in a certain year and month, for example all media uploaded in December 2022, then we can use a filter first before deleting all media, but because in this tutorial we will delete all media in WordPress, we can choose the All Dates.

Cara Menghapus Semua Media WordPress - 1-4

option. After deciding whether to delete all media or media in a certain month, we can then select all media by checking or ticking the option next to the File.

Cara Menghapus Semua Media WordPress - 1-5

menu. Finally, in the last step, we can delete all media by selecting the dropdown Bulk Actions then choose Delete Permanently and click the Apply

Cara Menghapus Semua Media WordPress - 1-6

button. Later, a notification alert will appear to confirm with us whether the process will be continued or not, because if the process is continued, all data will be permanently deleted and cannot be restored if we do not have a backup.

Cara Menghapus Semua Media WordPress - 1-7

Option 2: Deleting All Media Using the Database

This method can be said to be more complicated and might cause website errors if you use the wrong query. So once again, make sure you have created a website and database backup before using this method.

Because this method also requires access to the database, make sure you have obtained or know the database name used on the website whose media you want to delete. Do not make a mistake in performing the deletion and selecting the database.

To start the deletion, we need to delete all contents inside the uploads folder located inside wp-content, or we can also directly delete the uploads folder and then create a new uploads folder so that its contents are still empty.

Cara Menghapus Semua Media WordPress - 2-1

After the uploads folder is deleted, we are not finished yet because if we open the media page, the list of media still appears on our website, but when clicked, it does not display any media.

Cara Menghapus Semua Media WordPress - 2-2

Here we need to run a database query to delete all empty media on the WordPress dashboard page, so just open our WordPress installation database to continue the deletion.

On the database page, look for the table used to store media information, which is usually in the wp_poststable. It should be noted that wp_ is a prefix on the WordPress table where each WordPress installation might use a different prefix .

Cara Menghapus Semua Media WordPress - 2-3

The prefix used in this tutorial is wpfh_, so the table name that needs to be opened is wpfh_posts. Please adjust it to your WordPress table prefix.

From the _poststable page, we need to run a deletion query so we can open the SQL panel that can be found in the row of menus at the top.

Cara Menghapus Semua Media WordPress - 2-4

Use the following query to delete all media information stored in the database. Make sure to change wpfh_ according to your WordPress database prefix.

DELETE FROM wpfh_posts WHERE post_type = 'attachment';

After the query is entered, click the Send or Go button to run the query and delete the media information whose files we have already deleted from our WordPress dashboard.

Cara Menghapus Semua Media WordPress - 2-5

Depending on how much media needs to be deleted, the time required to run the query will certainly vary. But if it is successful, we will get a message that is more or less like this.

Cara Menghapus Semua Media WordPress - 2-6

Now if we return to the media page on the WordPress dashboard, all the empty media that were previously displayed will disappear.

Cara Menghapus Semua Media WordPress - 2-7

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...