Make WordPress Core

Opened 2 months ago

#49339 new defect (bug)

Issue when comparing old and new meta of type integer on update_multi_meta_value

Reported by: renathoc Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: REST API Keywords:
Focuses: rest-api Cc:


Hi there!

I found an issue when updating a meta through JS (REST API). I'm using a plugin sidebar to update a post meta with the type integer.

When I update the meta value, the WP_REST_Meta_Fields::update_multi_meta_value method tries to compare the old and the new values to remove and add only the necessary.

But the $current = get_metadata( $meta_type, $object_id, $meta_key, false ); line always return an array of string and the $values is correctly an array of integer. So any value doesn't match, and all old post metas are deleted and all new post metas are added.

The line that tries to compare is: $remove_keys = array_keys( $to_remove, $value, true );


  • We have as a post metas: [ 1, 2 ] and try to update for [ 2, 3 ]
  • It's removing the 1 and 2. And after that it's adding the 2 and 3
  • It should remove the 1 and add the 3


As a workaround, I'm thinking to use temporarily get_post_metadata to return the value correctly (as integer).

The steps to reproduce:

I created a clean repo with the scenario to make it easier to simulate: https://github.com/renatho/meta-type-test-plugin/tree/master

  • Clone the repo
  • Run npm i && npm run build.
  • Add the plugin to a WP env.
  • Go to a post.
  • Click on the smile on the top right.
  • Change between the options clicking on the buttons and saving the post.
  • Check the post comments to see the result.

Change History (0)

Note: See TracTickets for help on using tickets.