0

I am capable of fetching private posts through the wp rest api by calling

mydomain/wp-json/wp/v2/posts?status=private&slug=whatever

I am authenticating well and receiving a valid token, no problems

But with the same site running with Laragon (windows 10), while running ok with the authentication, I cannot retrieve the private posts

http://testing.test/wp-json/wp/v2/posts?status=private&slug=whatever

{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): status",
    "data": {
        "status": 400,
        "params": {
            "status": "Status is forbidden."
        }
    }
}

I'm getting the same response (as expected) when using Postman and having the Bearer token header correctly configured

What's going on? I've run out of ideas

*I can retrieve public posts

  • Here's the check. Are you sure current_user_can( $post_type_obj->cap->edit_posts ) || current_user_can( $post_type_obj->cap->read_private_posts ) ? It might be worth adding some error_log trace around those lines. – Rup Jan 10 at 14:20
  • Yes, that was it, I didn't install a plugin that enabled what you say, thanks! – GWorking Jan 10 at 14:23
  • @GWorking can you write an answer explaining what the problem was and naming the plugin you needed? If other people have the same issue they're going to want to know what fixed things for you ( also I can't upvote your answer if you don't write one! ) – Tom J Nowell Jan 10 at 15:26
  • Done (just waiting if @Rup wanted to post an answer) – GWorking Jan 10 at 18:21
  • No, there were lots more details than I had. Glad you solved it! – Rup Jan 10 at 18:23
1

The problem was that I didn't completely clone the wp site, and I forgot to install the plugin that I used to manage user roles

The plugin is Members ("User Role Editor by Members – Best User, Role and Capability Management Plugin for WordPress") by MemberPress, and there I can allow the roles that I want to have permissions to read private posts

Once that is done, the problem is gone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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