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.
![](https://itnursery.com/wp-content/uploads/2022/05/1653574379_apple-touch-icon@2.png)
2 Answers
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.