chmtt
chmtt

Reputation: 475

WP REST API - Get category name instead of id on post request

is there any solution to get the category name instead of id in the response on following endpoint? /wp-json/wp/v2/posts/:post_id

Thanks Guys

Upvotes: 11

Views: 9262

Answers (2)

M.A Shahbazi
M.A Shahbazi

Reputation: 1081

By adding the _embed query parameter to the endpoint, you can also retrieve categories.
It will be populated under _embeded object and then you can access it under wp:term in the JSON response.
Here's an example of how to do it for posts:

{{site}}/wp-json/wp/v2/posts?_embed=

Notice that _embed can get different values. For example, if you only need to embed wp:term (includes categories and tags) in the final result you can do this:

{{site}}/wp-json/wp/v2/posts?_embed=wp:term

Upvotes: 9

Bikram Pahi
Bikram Pahi

Reputation: 1183

WP REST API doesn't provide category name in '/wp-json/wp/v2/posts/:post_id' you can call another API request to get category name: /wp/v2/categories/<id>

For more details visit WP REST API

Upvotes: -3

Related Questions