I rewrote the function from the link in your question to SQL.
Keep in mind that this script will also clear the page-templates assigned to the pages.
Make a backup of the wp_postmeta table first.
DELETE pm
FROM wp_postmeta pm LEFT JOIN wp_posts p ON pm.post_id = p.id
WHERE
(p.post_type IN ('post', 'page') AND pm.meta_key <> '_thumbnail_id')
OR (p.post_type="attachment" AND pm.meta_key <> '_wp_attached_file'
AND pm.meta_key <> '_wp_attachment_metadata')
Related Posts:
- Delete all post meta except featured image
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- How to solve slow WordPress site caused by attachment_metadata
- Set Display Name to first and last name (phpmyadmin SQL Query)
- Size article thumbnails and retrieve them directly from database
- Emojis getting converted to “?”
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- WordPress database import: Row size too large
- Changing root password in PHPMyAdmin for WordPress Database when going live
- Can’t update WordFence Options, clear data manually
- Files on Localhost, Database on Server
- Installing local to live WP into subdirectory
- DB prefix not updating
- I wanted to Know that how can I give ingore to 0000-00-00 in my config file
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- “BS_” rows in postmeta table
- Migrating meta_key and meta_value from old theme to new one
- mySQL database size large, but tables size less
- Missing latest posts and options after DB migration via phpMyAdmin
- Check if a database is well installed
- How do i get value from wp_postmeta?
- featured image not showing up with mysql_connect
- SQL query : Select a thumbnail for a media
- Deleting WordPress posts and media files based on author via MYSQL database
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- importing a CSV into phpmyadmin
- Checking if Database Table exists
- The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?
- How to fetch Data in WordPress using MySQLi or $wpdb
- Connect to database using wordpress wp-config file
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- How to define composite keys with dbDelta()
- Is it possible to define two databases for one installation?
- Dealing with Many Meta Values, 30+
- What is the most secure way to store post meta data in WP?
- importing data from non-wordpress mysql db
- Huge wp_options table
- “MySQL server has gone away” since update to 3.8
- Error establishing a database connection – with Debug Data
- How to execute mulitple statement SQL queries using $wpdb->query?
- Does thumbnail regeneration edit the database?
- Can I transfer a mysql database to another site?
- Database with mixed collation (utf8mb4 & utf8_general_ci)
- MySQL Syntax Error upon restoring database from backup [closed]
- Help running a MySQL query to update all wp_#_options tables in a Multisite install
- Is it safe to convert tables from MyISAM to InnoDB?
- How to delete posts that does not have a thumbnail?
- Migrating database / content of non-CMS site to WordPress
- How do I properly update the WordPress database password?
- wpdb_prepare with multiple or condition
- Accidentally deleted active_plugins portion of the wp_options DB table
- WordPress Install and Database on separate hosting?
- delete post meta from db, even if does not exist?
- Where does the actual data stored by add_post_meta
- Error establishing database connection – high traffic?
- Using GROUP CONCAT in my-sql query with wp_usermeta table
- Routine to convert custom post meta from old to new value
- Create table from array with prepare
- How to prevent/delay MySQL connections when an object cache is used?
- Uknown meta entries in wp_postmeta
- Does post_meta data need to be unserialzed?
- Error establishing a database connection,
- Changing between Local Host DB to Production DB and in reverse
- Post Views / Hit Counter Problem?
- How and where is wordpress adding mySQL content to database?
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- Link image with data from the wpdb
- SELECT SQL_CALC_FOUND_ROWS with wordpress search
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- $wpdb->get_var – What value is returned when zero records are found?
- Remote database -> massive response time increase?
- Custom Post Type not showing anything added by code anymore?
- Getting “Error Establishing a Database Connection” on localhost in new Mac OSX Lion environment
- Cloning blog to localhost via WAMP
- Delete user with only subscriber role
- Can’t log into wordpress site – I have made a new user and still cant access
- Counting post and changing roles in mysql database. Query not code
- How to save EXIF metadata in WordPress database?
- How to edit custom table data in frontend
- local wordpress broke after changing URL
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- WP website showing blank page after moving from subdomain to main domain
- How to create index (sql) to a meta_key?
- Database structure for thousands of posts
- WPCLI search and replace in a particlar site dir effect another site-dir
- After renaming MySQL database, I can no longer access my Blog page
- Hang Up Followed By Can’t select database
- WordPress character set issue
- Create a new table on the database and save parameters from a contact form
- Changed meta_key value in structures, now dashboard shows zero users
- Why is converting my database to UTF-8 truncating entries?
- Database question while Migrating from one domain to another on same WebHost [Bluehost]
- How to back-up a database on IIS
- Export posts with postmeta without ID?
- export individual posts to text files or a single csv file
- WordPress database connection failed, while mysql client is working [closed]
- SQL errors when querying for something with apostrophes