Tuesday, June 28, 2022
HomeWordPress Developmentplugin growth - update_callback shouldn't be working in register_rest_field

plugin growth – update_callback shouldn’t be working in register_rest_field


I’m registering a brand new area in my customized put up kind utilizing register_rest_field.

However I’m unable so as to add/replace the sector utilizing the remainder API of put up add/edit. Nonetheless, the get_callback operate is working superb.

The pattern code is just like the under –

register_rest_field('my_post_type', 'my_field', [
  'get_callback' => function ($params) {
    return get_post_meta($params['id'], 'my_field', true);
  },
  'update_callback' => operate ($worth, $object){
    return update_post_meta($object->ID, 'my_field', $worth);
  },
  'schema'       => [
     'description'       => __( 'Array of the ids', 'textdomain' ),
     'type'              => 'array',
     'items'             => [ 'type' => 'integer' ],
  ],
]);

Thanks prematurely!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments