WP Manifestindependent plugin directory
manifest / developer / clean-up-leftover-multi-meta

Clean Up Leftover Multi-Meta

Remove duplicate meta values for any single meta key with multiple meta value rows in the database.

★ 1stars
312composer installs
v0.1.0latest · 4 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/kadamwhite/clean-up-leftover-multi-meta/archive/refs/heads/main.zip

On Packagist as humanmade/clean-up-leftover-multi-meta:

composer require humanmade/clean-up-leftover-multi-meta
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

There is a potential bug in the REST API (identified by @MiguelAxcarHM, and being discussed between @TimothyBJacobs and @kadamwhite here in WordPress core Slack) where updates to meta values can fail unexpectedly because of unrelated other meta.

Our working theory is that this happens when a meta key is registered (using register_meta or register_post_meta) with 'single' => true, but that meta key still has multiple rows in the database as you would expect if it was previously used as 'single' => false. For example,

+---------+---------+---------------------------------------------+---------------+
| meta_id | post_id | meta_key                                    | meta_value    |
+---------+---------+---------------------------------------------+---------------+
|    8898 |    5804 | process_owner                               | 333           |
|   11870 |    5804 | process_owner                               | 333           |
|   13868 |    5804 | process_owner                               | 333           |
|   15748 |    5804 | process_owner                               | 333           |
+---------+---------+---------------------------------------------+---------------+

This plugin provides a CLI command which can be used to iterate through all posts of a post type, check for registered meta for that post, and identify whether any single-registered meta keys have duplicated rows in the postmeta table. The duplicated meta IDs are then cleaned out.

If a meta key has multiple rows for a post with different values, we should leave those alone.

Example command:

wp clean-up-leftover-multi-meta --post-type=my-cpt-name --dry-run

Releases

1 release.

Tag
Published
v0.1.0 latest
Sep 26, 2022 4 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.