Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 583
chmtt Avatar asked Nov 26 '22 01:11

chmtt


1 Answers

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
like image 54
M.A Shahbazi Avatar answered Feb 17 '23 12:02

M.A Shahbazi