WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Related to my How do I create a custom post type for a training CMS in WordPress? question, I would like to know how I can create a private comments section for a custom post type (or any post type for that matter, if possible), where these comments are only visible to their author. I am working on a training CMS and students should be able to make private study notes on the training content pages as they work through them.

share|improve this question

Comments have an associated author to them.

In a section called "Private Comments" - Query for all comments belonging to the current post where wp_comments->comment_author_email equals the email of the current user.

Checkout the wp_comments table. It has 15 or so fields you can filter when displaying comments.

EDIT: The code would look something like this:

 $comment_array = get_approved_comments($post->ID);

 $current_user = wp_get_current_user();

   foreach($comment_array as $comment){
      if ($comment->comment_author_email == $current_user->user_email) {
              echo $comment->comment_content ;


You loop through the list of comments for the current post and filter by author email.

share|improve this answer
thanks, but how do I create such a section? – ProfK Dec 15 '11 at 11:04
please check my edit. – rexposadas Dec 15 '11 at 18:17
Thanks again, you've been very helpful, but I'm really asking how do I have a 'Private Comments' section on a post? Do I use a metabox or something? – ProfK Dec 16 '11 at 5:09

You don't need to add a metabox, just amend the code that displays the comments - the actual code you will need to replace will depend on which theme you are using.

However, please note that you should avoid comparing the comment e-mail address with the current logged-in user e-mail address as suggested above as a registered user can change their email address. This does not then change the email address used on existing comments so only comments made after their email address was changed would be displayed.

Probably better to compare user-IDs:

if ($comment->user_id == $current_user->ID
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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