简体   繁体   中英

Return comments with WP-API Post data

I'm using the WP-API plugin as a RESTful API to my Wordpress site. I want the comments associated with a post to return from the /posts/:id endpoint. The docs indicate that this is possible by passing a withcomments filter, however I can't get this to work. I've tried the following with no success:

http://climbingnarc.com/wp-json/posts/24001?filter[withcomments]=1

http://climbingnarc.com/wp-json/posts/24001?filter[withcomments]=true

I do know that http://climbingnarc.com/wp-json/posts/24001/comments works, but I don't want to have to make a separate request just for the comment data.

Is there a correct way to use this filter so that comments are returned with the post data?

Try ?_embed=1 in your request; that ought to bring down all embedded data, including comments, alongside the requested post. K.Adam White

This works for me.

Source

在Github上打开了一个关于此的问题 ,它被标记为Enhancement ,所以我假设这在当时还行不通。

Have the same problem. Working on a mobile app and don't want the users to make unnecessary API calls so I decided to make a plugin for.

https://github.com/shahin8r/comments-posts-wp-api

Let me know if you find it useful.

This is a bit after the fact, but this worked for me : "/wp-json/posts/{{post id}}/comments/". I'm a big fan of climbing narc! Hope this helps someone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM