wp-post-meta-revisions icon indicating copy to clipboard operation
wp-post-meta-revisions copied to clipboard

Non-unique meta-key are saved together in autosave

Open grappler opened this issue 4 years ago • 0 comments

We are using CMB for the custom meta boxes. (I know it is deprecated but waiting for a whole site refresh to migrate away).

There is a non-unique meta key ph_tabs with an array as value. The data is saved as follows in the database image

The metadata for the autosave is fetched from $_POST.

https://github.com/adamsilverstein/wp-post-meta-revisions/blob/ca459926808b025c256654962e577c91597dd0e0/wp-post-meta-revisions.php#L76

Plugins like CMB send the data in a array and this caused for the data to be saved as one big array instead of seperate rows for each array.

This is how the $_POST looks like:

Array (
[ph_tabs] => Array (
    [cmb-group-0] => Array (
            [ph_tab_title] => Array (
                    [cmb-field-0] => New tab
            )
            [ph_tab_content] => Array  (
                    [cmb-field-0] => Content
            )
    )
    [cmb-group-2] => Array (
            [ph_tab_title] => Array  (
                    [cmb-field-0] => Tab Title
             )
            [ph_tab_content] => Array (
                    [cmb-field-0] => Content second tab
             )
     )
)
)

I will create a PR with a fix.

grappler avatar Sep 23 '21 09:09 grappler