Opened 8 years ago
Closed 8 years ago
#38607 closed enhancement (fixed)
Add `rest_base` to response objects of `wp/v2/taxonomies` and `wp/v2/types` on the REST Api
Reported by: | youknowriad | Owned by: | joehoyle |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | rest-api | Cc: |
Description
As noted by @jnylen0 on this ticket https://core.trac.wordpress.org/ticket/38439#comment:8 currently there's not a way to programmatically link the taxonomy parameters to the term endpoints or the post type items to the corresponding post endpoints.
This ticket aims to add the rest_base
attribute to the corresponding endpoints.
Attachments (4)
Change History (17)
#3
@
8 years ago
Previously discussed in https://github.com/WP-API/WP-API/issues/1381
We want to avoid exposing the raw value of rest_base
in favour of exposing links that use them. Exposing the raw value encourages manual URL building, but we're trying to heavily encourage using the URLs. This may change based on #38439 however.
#4
@
8 years ago
Here's one example of a link that is currently missing:
- The
note
post type supports categories: https://nylen.io/blog/wp-json/wp/v2/taxonomies/category - How do I get items of the
note
post type? (Itsrest_base
isnotes
but there's no way to tell that from here)
Once taxonomies are added to post types in #38438 there will be a similar situation, but in reverse: going from a post type in /wp/v2/types
to its taxonomies.
#5
@
8 years ago
Oh! I see. I added a second patch. This time I add a link to post_types on the taxonomy endpoints. @jnylen0 We can do the same on the /types
endpoint when we add taxonomies.
#6
@
8 years ago
I am +1 for this. We should return the WP_Post_Type and WP_Taxonomy objects in these responses, and the rest_base
property is a part of those objects.
#7
@
8 years ago
@youknowriad @jnylen0 post-type-links.patch looks like it may belong to another ticket?
#8
@
8 years ago
The links patch is in response to https://core.trac.wordpress.org/ticket/38607#comment:3:
We want to avoid exposing the raw value of
rest_base
in favour of exposing links that use them
#9
@
8 years ago
Given the decision in #38439, rest_base
is no longer useful for building URLs. We should still add it though. Here's another example where it would be useful:
- I'm looking at a taxonomy response e.g.
/wp/v2/taxonomies/post_tag
- I follow the
collection
link to find some interesting terms in this taxonomy - I want to add one of these terms to a post. Which property name do I use?
In step 3 I want the taxonomy's rest_base
, but it's not available. Currently the only way I see to get it is by looking at the last piece of the collection
URL.
#10
@
8 years ago
- Milestone changed from Awaiting Review to 4.7
38607.diff is rest-base.patch from @youknowriad, refreshed against latest trunk. Let's get this simple and helpful change in 4.7.
#11
@
8 years ago
Updated patch with schema type => string
fix, and also used the $base
vars to account for rest_base
not existing on the post type / taxonomy.
Proposed patch