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

后端 未结 1 1994
野趣味
野趣味 2021-01-03 14:18

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 currentl

相关标签:
1条回答
  • 2021-01-03 14:42
    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;
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题