can’t access custom field in the meta json

[ad_1]

hi

i have a custom post type book, and in its args i have

'show_in_rest'  => true,

now i want to add a custom field to it like so:

add_action( 'init', 'add_to_rest_test' );

function add_to_rest_test(){
   $meta_args = array(
      'type'         => 'string',
      'description'  => 'A meta key associated with a string meta value.',
      'single'       => true,
      'show_in_rest' => true,
   );
   register_post_meta( 'book', 'testing_field', $meta_args );
}

but then when i go to the post json: myexamplesite/wp-json/wp/v2/book…. there is no “meta” section. But if i change the code to regular post:

register_post_meta( 'post', 'testing_field', $meta_args );

in the json i do have a meta section:

"meta": {
    "testing_field": "",
    "footnotes": ""
  },

what am i missing here? appriciate any help

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer