[wp-trac] [WordPress Trac] #47866: Document that register_meta's show_in_rest for Custom Post Types requires custom-fields support

WordPress Trac noreply at wordpress.org
Mon Aug 12 23:08:42 UTC 2019


#47866: Document that register_meta's show_in_rest for Custom Post Types requires
custom-fields support
--------------------------+--------------------
 Reporter:  kadamwhite    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  5.3
Component:  REST API      |    Version:  4.9.8
 Severity:  normal        |   Keywords:
  Focuses:  docs          |
--------------------------+--------------------
 As noted previously in #40408 and captured in a [https://github.com/WP-
 API/docs/issues/51 REST API handbook ticket], a custom post type must
 include `custom-fields` in its `supports` array or the `meta` key will not
 appear in REST API responses even if that meta is properly registered
 using `register_meta`.

 This is true for both `register_meta` and the derivative
 `register_post_meta` method, as in the below rough example:
 {{{#!php
 <?php
 register_post_type( 'book', array(
     'public'       => true,
     'show_in_rest' => true,
     'supports'     => array( 'title', 'editor' ),
 ) );
 register_post_meta( 'book', 'awards', array(
     'show_in_rest' => true,
     'single'       => true,
     'type'         => 'integer',
 ) );
 }}}
 The `meta` key will be missing from the REST API responses for the `book`
 post type in this example because `custom-fields` is not included in the
 `supports` array.
 As meta over REST becomes more important to the block editor and complex
 plugins, I propose we expand the documentation of the `show_in_rest`
 argument for `register_meta` to highlight this caveat.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47866>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list