[wp-trac] [WordPress Trac] #45220: register_rest_field doesn't work

WordPress Trac noreply at wordpress.org
Mon Oct 29 15:40:16 UTC 2018


#45220: register_rest_field doesn't work
-------------------------------+------------------------------
 Reporter:  Dudo               |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  REST API           |     Version:  5.0
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by Dudo):

 Hi, thank you for your response.

 It is very simple:

 {{{#!php
 <?php
 add_action( 'rest_api_init', 'yasr_rest_comment_meta' );

 function yasr_rest_comment_meta() {

         register_rest_field(
                 'post',
                 'yasr_overall_rating',
                 array(
                         'get_callback' => 'yasr_rest_get_overall_rating',
                         'update_callback' => null,
                         'schema' => null,
                 )

         );

 }

 function yasr_rest_get_overall_rating () {

         $overall_rating = yasr_get_overall_rating();

         return $overall_rating;

 }

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45220#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list