79770923

Date: 2025-09-21 14:56:06
Score: 0.5
Natty:
Report link

Your postmeta is huge brother

Before HPOS, WooCommerce stored orders as post_type = shop_order in the wp_posts table and all order data in wp_postmeta.
Now with HPOS, orders live in:

But WooCommerce does not automatically delete the old shop_order posts or their postmeta (for backward compatibility). That’s why your wp_postmeta is still bloated.

Safe Cleanup Steps

1. Check how many old orders are still in wp_posts

SELECT COUNT(*) 
FROM wp_posts 
WHERE post_type = 'shop_order';

If you’ve fully migrated to HPOS, you don’t need these anymore.

2. Remove old order postmeta

This query deletes all postmeta records tied to old shop_order posts:

DELETE pm
FROM wp_postmeta pm
INNER JOIN wp_posts p ON pm.post_id = p.ID
WHERE p.post_type = 'shop_order';

3. Remove old order posts

DELETE FROM wp_posts
WHERE post_type = 'shop_order';

4. Optimize the table

OPTIMIZE TABLE wp_postmeta;

Stage Cleanup - its optional:

Because you’ve got 9M+ rows, deleting everything in one go can lock tables and time out.
Do it in batches like this:

DELETE pm
FROM wp_postmeta pm
INNER JOIN wp_posts p ON pm.post_id = p.ID
WHERE p.post_type = 'shop_order'
LIMIT 50000;

Run multiple times until rows are gone. Cheers.

Reasons:
  • Blacklisted phrase (1): Cheers
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Jer Salam