Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#39976 closed defect (bug) (maybelater)

Taxonomies and Types should return rewrite info

Reported by: wonderboymusic Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords:
Focuses: Cc:


Taxonomies and Types behave similarly in the REST API endpoints that bear their fruit.

slug is actually the id of the object
name is the "label" for publicly identifying the taxonomy as text

There is, however, no representation of what the "pretty" version, or "slug", is for the taxonomy.

As an example:
post_tag is the ID
"Tags"/"Tag" is the label (it would be nice to also have labels returned tho....)
... missing info: what is the slug representation of post_tag - the answer is tag, but this info is missing from the REST API response.

Why is this important?

If food.whatever.com is reading REST API data from services.taco.com, and providing URLs on its site for arbitrary terms, it makes sense to create the routes to this terms as /{taxonomy.pretty}/{term.slug} - right now, the slug is post_tag, not tag. /post_tag/burrito is not as nice as /tag/burrito

Devs are also encouraged to namespace their registration, so taxonomies on the NYT would have a a registration value of nyt_kicker, which might be displayed as column - which is nowhere to be found in the response.

Change History (4)

This ticket was mentioned in Slack in #core-restapi by wonderboymusic. View the logs.

4 years ago

#2 @rmccue
4 years ago

Generally speaking, I'd like to avoid providing raw values (like the rewrite slug), and replace them with better ways to achieve the actual goal. Typically, this is via linking; we don't expose rest_base, but rather expose that via a link.

For rewrites, rather than just expose the value, the main thing they're used for is building URLs. Generally speaking, building URLs is a Bad Idea (since each URL is individually filterable), but there is utility in it.

There's two things we want here: a link to the taxonomy page, and a way to build term links. What if we add a new link with something like "item": { "href": "http://example.com/this_tax/{slug}" } (using URL Templates)? Would that cover this use case?

#3 @joehoyle
4 years ago

Pinging @wonderboymusic for a response on @rmccue's question.

#4 @wonderboymusic
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

This can be accomplished sufficiently by creating new endpoints with more data: https://github.com/staylor/wp-graphql-middleware/blob/master/lib/REST/Controller/Taxonomies.php#L21

Note: See TracTickets for help on using tickets.