plugin development – update_callback is not working in register_rest_field

Question

I am registering a new field in my custom post type using register_rest_field.

But I am unable to add/update the field using the rest API of post add/edit. However, the get_callback function is working fine.

Sample code is like below –

\register_rest_field('my_post_type', 'my_field', [
  'get_callback' => function ($params) {
    return \get_post_meta($params['id'], $meta['key'], true);
  },
  'update_callback' => function ($value, $object, 'my_field'){
    return \update_post_meta($object->ID, 'my_field', $value);
  }
]);

Thanks in advance!

0
Rajib Dey 1 month 2022-06-27T15:19:06-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse