最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What is an endpoint for custom post type comments in REST API?

programmeradmin3浏览0评论

In my react project i am using worpdress as backend and need to use my custom post type events comments also.

So as per the WordPress documentation for comments API i am using an endpoint like this “/wp/wp-json/wp/v2/comments?events=704”; so according to this it should display only 704 post-ids comments.

But in my case it returns me all the comments which are posted in the post_type = post also. See below JSON result of the above API endpoint for custom post type.

Here is a 'post_type' => post comment's data that returns a correct result.

I have passed this argument in the register_post_type 'show_in_rest'=> true

In my react project i am using worpdress as backend and need to use my custom post type events comments also.

So as per the WordPress documentation for comments API i am using an endpoint like this “/wp/wp-json/wp/v2/comments?events=704”; so according to this it should display only 704 post-ids comments.

But in my case it returns me all the comments which are posted in the post_type = post also. See below JSON result of the above API endpoint for custom post type.

Here is a 'post_type' => post comment's data that returns a correct result.

I have passed this argument in the register_post_type 'show_in_rest'=> true

Share Improve this question asked Aug 2, 2019 at 6:29 TMATMA 20012 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Custom post types are still posts, so to retrieve comments for a specific post of a custom post type you use the post argument. From the API reference:

post Limit result set to comments assigned to specific post IDs.

So:

json/wp/v2/comments?post=704
发布评论

评论列表(0)

  1. 暂无评论