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.

enter image description here

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

enter image description here

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

1 Answer 1

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
2
  • Okay, so by doing this i am getting this error message: prnt.sc/onbfvm
    – TMA
    Aug 2, 2019 at 6:51
  • Seems self explanatory to me. You don't have read permissions for comments for that post. That can happen if the post (or 'event') isn't published, you don't have its read capability or the post type isn't in REST. Aug 2, 2019 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.