How to realize following functionality by means of WP-Rest. It is necessary on other page (control of a plug-in, I write the plug-in), to remove select with custom post type, and after the choice, are updated below the field, in dependence of a post. If it is necessary, I can pay a small money for the help.
My code add custom field in WP-REST, but it doesn't work.
add_action( 'rest_api_init', 'create_api_posts_meta_field' );
function create_api_posts_meta_field() {
// register_rest_field ( 'name-of-post-type', 'name-of-field-to-return', array-of-callbacks-and-schema() )
register_rest_field( 'parsing', 'parsing_night_key', array(
'get_callback' => 'get_post_meta_for_api',
'schema' => null,
)
);
}
function get_post_meta_for_api( $object ) {
//get the id of the post object array
$post_id = $object['id'];
//return the post meta
return get_post_meta( $post_id );
}