My site has a custom role ("coach") with its own set of capabilities (via
map_meta_cap along with a few built-in roles). Each user is assigned a page on the site that they "own" and can edit (via a front-end editor).
Each page has comments (rebranded as "reviews").
This system works pretty well, except for one thing: WordPress won't return comments on pages that this user (with the "coach" role) doesn't 'own'.
I'm getting comments with
get_comments(), and it returns exactly what I expect if I'm logged out, logged in as an administrator, or logged in as a 'coach' and viewing that coach's page. When logged in as a 'coach' and viewing another page,
get_comments() returns an empty array.
This seems like a role/capability issue, but I'm having a hard time pinning down exactly what's happening. I've played with adding various capabilities to the coach role, but with no luck.
Here's the code I'm using to return comments:
$testimonials = get_comments( array( 'post_id' => $coach_post_ID, 'status' => 'approve', ) );
var_dump( $testimonials ); returns an empty array, unless I'm logged in as that 'coach', an administrator, or logged out entirely.
The coaches have all the public
read capabilities enabled (
read_coach) and can otherwise see all the content on other coach pages.
I'm happy to provide any information you might need to help diagnose the problem. Thanks in advance!