How to display logged in users comments (only) on WordPress

I’m currently building a niche Q+A site using wordpress with which users can either log in and post questions or log in and answer questions.

Questions are currently being stored as posts, and answers stored as comments. I want question answerers to be able to log in and view all their comments (answers) on one page with a link to the original post (question).

Read More

I can easily list posts in this way (i.e. list all of the logged in users posts on one page i.e. their original questions) but cant seem to do this with comments (i.e. list all the logged in user’s answers on one page.) Is there any way to do this?

Related posts

Leave a Reply

1 comment

    1. Click on Settings > Discussions and set what you want from there. There is one option that lets only registered members to post a comment.
    2. http://pastebin.com/EJcghXAW – see code from line #39, same aproach also in your case.

    The query for the comments is the normal wordpress way, but you need to include it in the conditionals linked and pointed above.

    Usage example:

    <?php
    if ( is_user_logged_in() ) {
        $user_id = get_current_user_id();
        $args = array(
            'status' => 'approve',
            'order' =>  'DESC',
            'user_id' => $user_id
        );
        $comments = get_comments($args);
        foreach($comments as $comment) :
            echo '<p>'; 
            echo($comment->comment_author . '<br />' . $comment->comment_content);
            echo '</p>';
        endforeach;
    }
    ?>