Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Show list of members who have not yet commented on post WordPress

  • SOLVED

As the title states. I would like to show a list of members names who have not yet commented on the post.

Once they have commented on the post they will be removed from the list.

This is on a per post basis.

Theme is on a Multisite setup.

Answers (3)

2013-06-23

Hariprasad Vijayan answers:

Hello,

I think you can't get this result directly, you need to query it from database.


Hariprasad Vijayan comments:

You can try the following code, it works here

<?php
$getcommenteduserids = $wpdb->get_col("SELECT user_id FROM $wpdb->comments WHERE comment_post_ID = ".get_the_ID());
if ( $getcommenteduserids )
{
$user_query = new WP_User_Query( array( 'exclude' => $getcommenteduserids ));
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo '<p>' . $user->display_name . '</p>';
}
} else {
echo 'No users found.';
}
}
?>

Good luck..


Hariprasad Vijayan comments:

Please ask if you are facing any problem.


leannekera comments:

Works exactly as I wanted. Thank you Hariprasad

2013-06-23

Yakir Sitbon answers:

You need get ALL users from your WP system, and start a loop.. and check.. if current user get comment on this post.. skip them.. and if not, print his name.


leannekera comments:

Do you have a coded example?


Yakir Sitbon comments:

I start coding for you.. wait..


Yakir Sitbon comments:

Sorry.. I'm need to go right now, if you cannot get help here, I will help you later. sorry.


Yakir Sitbon comments:

global $wpdb;
$user_ids = $wpdb->get_col( $wpdb->prepare(
'SELECT `user_id` FROM %1$s
WHERE `comment_post_ID` = \'%2$d\'
AND `user_id` != \'0\'
GROUP BY `user_id`
;',
$wpdb->comments,
get_the_ID()
) );
if ( ! empty( $user_ids ) ) {
$site_users = get_users();
foreach ( $site_users as $site_user ) {
if ( in_array( $site_user->ID, $user_ids) )
continue;
echo '<p>' . $site_user->display_name . '</p>';
}
}

2013-06-23

Francisco Javier Carazo Gil answers:

Hi,

You can do this with it:


<?php
$blogusers = get_users('orderby=nicename'); // list with all users
$user_list = array();
foreach($blogsusers as $bloguser) :
$user_list[] = $bloguser->ID;
endforeach;

$comments = get_comments('post_id=" . get_the_ID() ."');
$commenters = array();
foreach($comments as $comment) :
$commenters[] = $comment->user_id;
endforeach;

$users_has_not_commented = array_diff($users_has_not_commented, $commenters);
?>
<ul>
<?php
foreach($users_has_not_commented as $not_commenter):
$user = get_user_by( 'id', $not_commenter );
echo $user->first_name . ' ' . $user->last_name;
endforeach;
?>
</ul>


Doubts?