admin管理员组

文章数量:1122832

I have this url mysite/wp-json/wp/v2/posts . it gets me all the posts I want, but what I need is the Parent ID of the Post. Is there an endpoint for example mysite/wp-json/wp/v2/parent/{postID} ??

I have this url mysite.com/wp-json/wp/v2/posts . it gets me all the posts I want, but what I need is the Parent ID of the Post. Is there an endpoint for example mysite.com/wp-json/wp/v2/parent/{postID} ??

Share Improve this question asked Sep 5, 2020 at 19:02 evara killerevara killer 1011 bronze badge 2
  • 1 Hey! As far as I know, posts can’t have parents, but pages can. So the page endpoint also provides you with the parent ID, but the post endpoint doesn’t. Does that help or am I misinterpreting your question? – FMJansen Commented Sep 5, 2020 at 19:58
  • I think it helps, thank you! – evara killer Commented Sep 5, 2020 at 22:01
Add a comment  | 

1 Answer 1

Reset to default 0

As posts can’t have parents, there is no endpoint to get the parent ID of a post.

However, pages can have parents, so the page endpoint should return a parent ID, among other things. So, by getting mysite.com/wp-json/wp/v2/pages, you should be able to get the parent attribute, which is “The ID for the parent of the object.” If you want just the parent, you could use _filter in your request.

本文标签: WordPress rest API get Posts parent by post ID