[wp-trac] [WordPress Trac] #42094: REST API: extend _fields parameter to selectively include nested fields in response JSON

WordPress Trac noreply at wordpress.org
Wed Oct 4 19:14:24 UTC 2017


#42094: REST API: extend _fields parameter to selectively include nested fields in
response JSON
-------------------------+----------------------------
 Reporter:  kadamwhite   |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Future Release
Component:  REST API     |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+----------------------------
 This enhancement has been broken out from #38131, which introduced the
 `_fields` query parameter to whitelist select fields for inclusion in the
 API response object.

 In the comments of that ticket @TimothyBlynJacobs uploaded a patch with
 support for nested fields, such as returning `title.raw` while omitting
 `title.rendered`:

 > [https://core.trac.wordpress.org/attachment/ticket/38131/38131.3.diff
 [patch 31131.3.diff allows]] specifying `title.raw` for just the raw title
 or `title` to retrieve both the raw and rendered title. This could also be
 used by controllers to only calculate the fields as necessary. I'm not
 sure whether this should be used to limit the fields queried ( I think
 that can be done in `WP_User_Query` but I'm not sure about the others ). I
 imagine some of the performance benefits here, besides response size,
 would be not filtering `the_content` if it wasn't a requested field, for
 instance.

 There's been discussion of how feasible it is to use these parameters to
 hint that certain types of data processing are unnecessary, but on its own
 the base use-case of "give me the raw API response without its rendered
 counterpart" in edit mode could significantly speed up initial load of
 editor interfaces on slow connections.

 This nesting feature has also been proven out in the plugin repository in
 [https://wordpress.org/plugins/rest-api-filter-fields/ the rest-api-
 filter-fields] and [https://wordpress.org/plugins/wp-rest-jmespath/ wp-
 rest-mespath], the former through the same `basefield.nestedfield` syntax
 and the latter through JMESPath.

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


More information about the wp-trac mailing list