[wp-trac] [WordPress Trac] #49648: WordPress 5.4 RC2 : _fields parameter doesn't get nested proprieties from custom attribute

WordPress Trac noreply at wordpress.org
Sat Mar 14 18:17:06 UTC 2020


#49648: WordPress 5.4 RC2 : _fields parameter doesn't get nested proprieties from
custom attribute
--------------------------+-----------------------------
 Reporter:  Dudo          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  5.4
 Severity:  minor         |   Keywords:
  Focuses:  rest-api      |
--------------------------+-----------------------------
 I've added a meta_key with register_meta, with this code


 {{{
 register_meta('post', 'yasr_overall_rating',
         array(
             'show_in_rest' => true,
             'single'       => true,
             'type'         => 'number',
             'auth_callback' => function() {
                 return current_user_can('edit_posts');
             }
         )
     );
 }}}


 I can reach the nested proprieties successful with this:

 {{{
 ?_fields=meta.yasr_overall_rating
 }}}


 But, I can't access the nested proprieties of a custom attribute, added
 with this code:



 {{{
     $visitor_votes_obj = new YasrDatabaseRatings();

     $yasr_vv_schema = array(
         'description'          => 'Yasr Visitor Votes Data',
         'type'                 => 'object',
         'context'              => array('view', 'edit'),
         'properties'           => array(
             'sum_votes' => array(
                 'type'  => 'integer',
             ),
             'number_of_votes' => array(
                 'type'        => 'integer',
             ),
         ),
     );

 register_rest_field(
         'post'
         'yasr-visitor-votes',
         array(
             'get_callback'    => (array($visitor_votes_obj,
 'getVisitorVotes')),
             'update_callback' => null,
             'schema'          => $yasr_vv_schema
         )
     );
 }}}

 I can reach successful the attribute **yasr-visitor-votes** with this:


 {{{
 ?_fields=yasr-visitor-votes
 }}}

 But I can't access the nested properties

 {{{
 ?_fields=yasr-visitor-votes.sum_votes
 ?_fields=yasr-visitor-votes.number_of_votes
 }}}

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


More information about the wp-trac mailing list