I have an endpoint in this address:
example/wp-json/wp/v2/myendpoint
I want to add a field to the endpoint with these codes:
add_action( 'rest_api_init', 'create_api_posts_meta_field' );
function create_api_posts_meta_field() {
register_rest_field(
'myendpoint',
'post-meta-fields',
array(
'get_callback' => 'get_post_meta_for_api',
)
);
}
function get_post_meta_for_api( ) {
$hello="Hello";
return $hello;
}
but it doesn't work. Please tell me whats wrong with my codes.