I’m building a front end using WP JSON, and I need (among other things) the name of the author of each post.
In V1, this was easy – here’s a fragment of a typical post object from calling http://example.com/wp-json/posts/1:
{
"ID": 1,
"title": "Hello world!",
"status": "publish",
"type": "post",
"author": {
"ID": 1,
"name": "admin",
"slug": "admin",
"URL": "",
"avatar": "http://0.gravatar.com/avatar/c57c8945079831fa3c19caef02e44614&d=404&r=G",
"meta": {
"links": {
"self": "http://example.com/wp-json/users/1",
"archives": "http://example.com/wp-json/users/1/posts"
}
}
},
But in V2, for author, all we get back is the ID (an integer). Passing this back to the API, we get a list of every article an author has written – but how can I get the author’s information – their name, avatar, etc.?
PS: boy the V2 documentation is sparse…V1 was much better…
Append the query parameter _embed in your API URL
Embedding is triggered by setting the _embed query parameter on the request. This will then include embedded resources under the _embedded key adjacent to the _links key in JSON file… as showed in http://v2.wp-api.org/reference/links.html
Examples:
Getting Author Name from JSON, and showing:
Getting Featured Image:
Categories:
and Tags:
I think what you want is
/wp-json/wp/v2/users/1
You should also find the direct url at
_links
>author
>href