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',
) );

Running 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 and 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!

1 Answer 1


I had the same issue, main users have the contributor role and a simple sidebar comment sidebar widget was not working when logged-in! Strange. I solved it by some sql:

function getLatestComments ( $postid ) {
    global $wpdb;
    $sql = "SELECT * from $wpdb->comments WHERE
             comment_post_ID = $postid AND 
             comment_approved = 1 
             ORDER BY comment_ID DESC";
    return $wpdb->get_results($sql);

I used this instead of get_comments. You may modify the sql and customize as required.

  • Thanks cenk! I'm going to give this a try and see what happens. Commented Jan 7, 2014 at 0:20

Your Answer

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

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