Make WordPress Core

Opened 8 years ago

Closed 5 years ago

#38132 closed feature request (wontfix)

Remove orphaned postmeta

Reported by: lukecavanagh's profile lukecavanagh Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords:
Focuses: Cc:


It seems like a feature to remove orphaned postmeta on a site should be something that is built into core.

I know you can remove orphaned postmeta by MySQL query or plugin, but this does seem like something that should be built into core.

WooCommerce has a similar function to removed expired session data from the options table built into core.

Change History (5)

#1 @jorbin
8 years ago

@lukecavanagh Can you clarify what you mean by 'orphaned' post meta. Do you mean post meta that is not registered by register_meta? Do you mean no longer used post meta? Do you post meta related to posts that have been deleted? Something completely different?

#2 follow-up: @lukecavanagh
8 years ago


This is more postmeta that is no longer being used, as well as post meta that was not removed when posts where deleted. But that post meta is still being stored in the postmeta db table.

#3 @SergeyBiryukov
8 years ago

  • Component changed from General to Options, Meta APIs

#4 in reply to: ↑ 2 @SergeyBiryukov
8 years ago

Replying to lukecavanagh:

This is more postmeta that is no longer being used

Is there a reliable way to determine that it's no longer being used?

as well as post meta that was not removed when posts where deleted.

wp_delete_post() does remove the associated post meta. If someone is deleting posts via direct SQL queries instead of using the WordPress API, seems like they should be responsible for cleaning up post meta as well.

#5 @desrosj
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I'm going to close this out as a wontfix.

I do not think Core should make assumptions about what post meta is "no longer being used".

  • There is currently no way to tell when post meta is updated or utilized.
  • It's not uncommon for post meta to be set once and never change.
  • If meta remains after using wp_delete_post() (or remains "orphaned", in general), then we should look into why this happens and fix it.
  • If a plugin, theme, or custom code is using a direct query to remove a post, then they should be educated on the benefits of using wp_delete_post().

Expired session data stored in transients, as referenced in the description, is a much different use case. Transients have an explicit expiration timestamp that defines when data should no longer be used.

Note: See TracTickets for help on using tickets.