How to Bulk Delete WordPress Custom Sections/Fields/Domains?

WordPressCustom columns are not only powerful, but also very practical. Many WordPress themes and plugins use custom columns to achieve various functions.

The article view statistics plugin WP-PostViews we use is to write custom columns in the database ▼

views

Used wordpress themes or plugins, after deactivation and deletion, usually retain their custom fields in the database.

If the amount of data is huge, every time the website queries the database, it will consume the RAM memory of the host, which will definitely affect the normal operation of the website.

We doSEO, to write more than one article, if you manually delete these garbage custom columns, it is not practical at all.

In fact, we only need tophpMyAdminExecute a SQL command to delete these garbage custom columns in batches in the database.

Please Note

Since WordPress deletes custom columns in bulk, it is related toMySQL databaseoperation, there are certain risks.

Therefore, be sure to make a database backup before you can perform database operations.

Method 1: Delete redundant custom columns with database commands (recommended)

1) After logging into the phpMyAdmin database, select your database.

2) Click on "SQL" above the database.

3) Enter and execute the following commands in "SQL":

DELETE FROM wp_postmeta WHERE meta_key = "自定义栏目名称";

4) Then, check the custom section in your website article to confirm whether it has been successfully deleted.

Method 2: PHP code to delete redundant custom columns

1) Please add the following code to the functions.php file of the current theme ▼

global $wpdb;
$wpdb->query( "
DELETE FROM $wpdb->postmeta
WHERE `meta_key` = '栏目名称'
" );

2) Modify "Column Name" to the custom column you want to delete.

  • The custom column will be automatically cleared from the database.

3) This code is only used when needed:

  • Be sure to delete it after completing the deletion task.
  • If you want to use it next time, please add it to the functions.php file of the current theme again,
  • Because it needs to be added and deleted, it is more troublesome, so it is not recommended.

Delete useless postmeta records

The log record may have been deleted, but the data in the log extension table postmeta has not been deleted, so it has only been cleared manually.

1) After logging into the phpMyAdmin database, select your database.

2) Click on "SQL" above the database.

3) Enter and execute the following command in "SQL" ▼

DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL

If your WordPress website, CPU, memory MEMORY usage is too high...

For the solution, please refer to this tutorial▼

 

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to delete WordPress custom columns/fields/domains in bulk? , to help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-175.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top