Creating a Comment History?
-
So I’m in the process of making a website that requires a login to post, but all posts are anonymous. A feature I’d like to implement is to allow users to track their own comments and jump to their posts, to see if anyone has responded recently. I’ve found the below way of doing it, which works okay except for the fact that someone can just enter another user’s username to see their comment history. Since a lot of this website is predicated on no one knowing who posts what, this is a huge flaw given the mission of my site. Is there any way to modify the below code such that, when I place it in a page, it’ll get the comment history only for the person currently viewing the page, as opposed to a static given user?
<? if(get_query_var('author_name')) : $curauth = get_userdatabylogin(get_query_var('author_name')); else : $curauth = get_userdata(get_query_var('author')); endif; $querystr = " SELECT comment_ID, comment_post_ID, post_title, comment_content FROM $wpdb->comments, $wpdb->posts WHERE user_id = $curauth->ID AND comment_post_id = ID AND comment_approved = 1 ORDER BY comment_ID DESC "; $comments_array = $wpdb->get_results($querystr, OBJECT); if ($comments_array): ?> <h2>Your Recent Posts</h2> <ul> <? foreach ($comments_array as $comment): setup_postdata($comment); echo "<li><a href='". get_bloginfo('url') ."/?p=".$comment->comment_post_ID."'>Comment on ". $comment->post_title. "</a><br />". $comment->comment_content . "</li>"; endforeach; ?> </ul> <? endif; ?>
- The topic ‘Creating a Comment History?’ is closed to new replies.