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
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- phpMyAdmin – Error > Incorrect format parameter?
- Why is my database import losing text widget data?
- Will it break my site if I delete all transient records in wp_options table?
- Why WordPress choose data serialization over json_encode?
- Please explain how WordPress works with MySQL character set and collation at a low level
- How to fetch Data in WordPress using MySQLi or $wpdb
- Connect to database using wordpress wp-config file
- Reset Post IDs to less than 64bit integer
- Does WordPress use the InnoDB engine for MySQL by default?
- Dealing with Many Meta Values, 30+
- What is the most secure way to store post meta data in WP?
- How to delete outdated, wrongly sized images in _wp_attachment_metadata?
- Why does dbDelta() not catch MysqlErrors?
- Huge wp_options table
- Custom DB_COLLATE (collation) value not working on fresh install?
- Export only pages and posts with mysql dump
- What causes the “max_user_connections” warning on WordPress frontend?
- what to do when your WordPress database is too large?
- WordPress and automated MySQL backups to a different host
- How Do I Merge Categories With phpMyAdmin
- WordPress site uses MyISAM, should I switch to InnoDB necessary?
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- WordPress mysql table double prefixes
- Storing data for a wordpress plugin
- Structure of postmeta meta_value for woocommerce product download
- Advanced SELECT query with condtional statements
- Why do mass updates to post_content shows in front end, but not in edit screen?
- Error establishing database connection – high traffic?
- Improve performance by removing unnecessary database queries
- Redirecting to old domain after migration website
- WordPress Database Huge wp_usermeta Table
- Switching Databases in LocalHost
- How to update the values when the featured image has changed?
- Unable to set a default serialized array using dbdelta()
- How to prevent/delay MySQL connections when an object cache is used?
- Uknown meta entries in wp_postmeta
- Error establishing a database connection,
- Changing between Local Host DB to Production DB and in reverse
- Post Views / Hit Counter Problem?
- Why does changing Database Table Prefixes result in loss of content?
- Query Column of Specific ID from Database Table
- Link image with data from the wpdb
- Moving WordPress site to new domain – database import [duplicate]
- SELECT SQL_CALC_FOUND_ROWS with wordpress search
- How to connect and insert data in database of wordpress?
- Buddypress avatar image in database [closed]
- 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?
- wp_option table error while importing
- Cloning blog to localhost via WAMP
- Only allow user to access a link once a year, based on their joining date
- 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?
- MSQL database wp_postmeta has meta key tve_revision
- How can I find user role in Mysql?
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- Featured image from custom to WordPress database
- WordPress Database Query works in phpMyAdmin but not in the code
- Duplicate database to roll back theme & content changes
- spambot registering without providing email or password, bypassing registration process
- After renaming MySQL database, I can no longer access my Blog page
- How To connect to the same WordPress database with different database user
- How much post meta data is too much?
- 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?
- Options table – where does my values go?
- 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
- why you don’t Implement PDO for access every thing to database
- How to find fresh (last modified) and sql backup?
- Uploading to WordPress Database