10

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

chmtt
  • 437
  • 4
  • 10

2 Answers2

3

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
M.A Shahbazi
  • 876
  • 9
  • 23
-3

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

Bikram Pahi
  • 1,107
  • 1
  • 12
  • 33