[wp-trac] [WordPress Trac] #64017: WordPress REST API returns 500 error when updating serialized meta with an unchanged value

WordPress Trac noreply at wordpress.org
Mon Sep 22 20:48:22 UTC 2025


#64017: WordPress REST API returns 500 error when updating serialized meta with an
unchanged value
-------------------------------+------------------------------
 Reporter:  wwccscorer         |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  REST API           |     Version:  6.8.2
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by wwccscorer):

 If it is of any use, below is the filter (taken from the second reference
 in the original ticket and modified appropriately for my metadata) which I
 use to prevent the problem from happening ;_
 {{{
 // Fix for WP REST API meta error when sending updated encoded JSON with
 no change
 add_filter( 'update_post_metadata' , function ( $value , $object_id ,
 $meta_key = false , $meta_value, $prev_value ) {

     $meta_type = 'post';

     $serialized_meta_keys = array('course_length',
                         'course_minslope',
                         'course_maxslope',
                         'course_minelev',
                         'course_maxelev',
                         'course_ascent',
                         'hq_name',
                         'hq_address',
                         'hq_postcode',
                         'hq_link',
                         'course_name_slug',
                         'event_date',
                         'event_start_time',
     );

     if ( defined('REST_REQUEST') && REST_REQUEST && in_array($meta_key,
 $serialized_meta_keys) ) {

         $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');

         if ( !$meta_cache ) {
             $meta_cache = update_meta_cache( $meta_type, array( $object_id
 ) );
             $meta_cache = $meta_cache[$object_id];
         }

         if ( isset($meta_cache[$meta_key]) ) {
             if ( $meta_value === $meta_cache[$meta_key][0] ) return true;
         }

     }

     return $value;
 }, 10 , 5 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64017#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list