If you use WordPress for your restaurant website, you might have different databases of items including your menu items, locations, promotions and even blog posts.
Some restaurants have large amounts of databases and require mass upload or mass deletion if anything goes wrong with the upload.
Today I am going to show you how to delete every WordPress post or custom post (menu item, location, etc) from your WordPress database so you can re-upload with a clean slate.
Different Methods To Mass Delete Posts
Mass Delete Manually – Best Way For Less Than 100 Posts
Mass Delete Posts Using A WordPress Plugin – Unreliable
Mass Delete Posts Using SQL – Best Way For 100+ Posts
If you have over 100 posts to delete, I recommend using this SQL method. Witht the SQL, all you have to do is insert the correct code (I will give yout he code), press a button, and all of the posts that was targeted by the code will be deleted in a matter of seconds.
To use SQL, you will have to go into your cPanel and access something called phpMyAdmin. phpMyAdmin is basically where all of your WordPress data is stored. You can manage all of your WordPress data in phpMyAdmin, including all of your WordPress posts.
First, log in to cPanel via your cPanel link or from a link provided by your hosting provider.
Once you are in your cPanel dashboard, use the search bar to search for “phpmyadmin” then click on “phpMyAdmin.”
After you click on phpMyAdmin, you will be redirected to your phpMyAdmin dashboard. It will look something like this:
From here, click on the SQL tab so you can copy and paste the code that I am about to give you to mass delete your posts.
When you copy and paste the code I am about to give you, your page should look like this:
Here is the code:
DELETE FROM wp{PREFIX}_posts WHERE post_type='{POSTNAME}’;
DELETE FROM wp{PREFIX}_postmeta WHERE post_id NOT IN (SELECT id FROM wp{PREFIX}_posts);
DELETE FROM wp{PREFIX}_term_relationships WHERE object_id NOT IN (SELECT id FROM wp{PREFIX}_posts)
There are a couple of modifications you might have to make to the code. The first modification is where I put {PREFIX} and the second modification is where I put {POSTNAME}. I will show you how to determine your prefix below.
Adjusting Your Database Prefix
First, you want to make sure that your wp_posts, wp_postmeta, and wp_term_relationships are correct. The way you can tell if this is correct is when you go into your database and see all your database names. Go back to the “Structure” tab and look at your database names and database prefixes. Make sure your database name is the correct one for your restaurant website. Then, get the correct prefix for that database:
So, if your restaurant website is the database on the top of the screenshot, then your prefix is wpkz. If your restaurant website database is the second database name in the screenshot, then your prefix is wpxt.
Adjusting Your Post Type
Now you need to adjust your post type in the code so that you only delete the post types tha you want to delete. As I said earlier, you might have different posts for different things on your website like menu items, locations, and more.
So, if you only want to delete menu items, then we will put the name of the menu item post type in the {POSTNAME} part of the code.
You can know what the name of your post type is by going into your wp{PREFIX}_posts database and looking at the post_type column. This will let you know which parts of your website are which post names:
So, from the screenshot above, if you wanted to delete all attachments, then you would insert “attachment” into the {POSTNAME} in the code.
After you have formatted your code correctly, you can paste it back into “SQL” tab:
DELETE FROM wpxt_posts WHERE post_type=’attachment’;
DELETE FROM wpxt_postmeta WHERE post_id NOT IN (SELECT id FROM wpxt_posts);
DELETE FROM wpxt_term_relationships WHERE object_id NOT IN (SELECT id FROM wpxt_posts)
STOP! Make sure that you don’t press the “Go” button just yet. You want to click on “Simulate query” first and see what would happen if you execute the code. You don’t want to accidentally delete anything you didn’t intend to.
Click on “Simulate query” and a box should pop up in a couple of seconds. Here is what mine looks like:
When you see the “Matched rows” count for each SQL query, you can cross-reference it to the number of posts that you know will be deleted. So if you know that you want to delete 100 menu items from your database and the “Matched rows” count says 100, then your query is probably correct.
If your query isn’t correct, go back and make the modifications you need to in order to mass delete the posts you intend on deleting.
If your query is correct, go ahead and press the Go button.
You have just easily deleted and cleaned up your WordPress restaurant website data!
In Conclusion
Being data savvy for your restaurant business will catapult your revenue and smooth out your operations far beyond your imagination.
The cleaner and more precise your data, the easier running your business will be.
When you need to mass delete data so you know that your next upload or update won’t have old data, the above way is the best way to do it.
What data have you needed to mass delete and upload or update?
Share below and let’s see how creative we can get with our data!