[wp-trac] [WordPress Trac] #47684: Embeddable 'self' links don't work on the REST API /search endpoint

WordPress Trac noreply at wordpress.org
Thu Jul 11 13:28:53 UTC 2019


#47684: Embeddable 'self' links don't work on the REST API /search endpoint
----------------------------+-----------------------------
 Reporter:  chrisvanpatten  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  REST API        |    Version:
 Severity:  normal          |   Keywords:
  Focuses:  rest-api        |
----------------------------+-----------------------------
 WordPress 5.0 introduced a new "search" endpoint which allows you to
 search across multiple types and subtypes.

 The responses are a "light" version of the full object responses, only
 including ID, type/subtype, title, and a few other small bits of data.

 They also include a standard links object:

 {{{
 _links: {
         about: [
                 {
                         href: "https://redacted/wp-json/wp/v2/types/post"
                 }
         ],
         collection: [
                 {
                 href: "https://redacted/wp-json/wp/v2/search"
                 }
         ],
         self: [
                 {
                         embeddable: true,
                         href: "https://redacted/wp-json/wp/v2/posts/43"
                 }
         ]
 }
 }}}

 In particular, note that the `self` link, a reference to the full object
 endpoint/response, is marked as embeddable. Thus, I would expect that a
 request to `/wp/v2/search?_embed=true` would include the full post
 response with each search result object.

 However, that's not the case — the embedding is completely ignored. This
 is because core
 [https://github.com/WordPress/WordPress/blob/abcbee954f4d8baa5aff2df566a942c1b48ca2d7
 /wp-includes/rest-api/class-wp-rest-server.php#L562-L565 intentionally
 skips past `self` links when "expanding" embeddable items]:

 {{{
 // Ignore links to self, for obvious reasons.
 if ( 'self' === $rel ) {
         continue;
 }
 }}}

 These reasons are indeed obvious when directly viewing the object —
 however in the search endpoint, where the responses are abridged, it would
 make sense to be able to embed the full object within your search results.

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


More information about the wp-trac mailing list