0

I'm basically using a 'latest comments' system on multiple pages where one specific user is listed as the first reply for a comment - highlighted with special CSS - and then 2-3 normal users below this 'special comment'.

I would like the specific user to be excluded from the list of normal users but I can't figure it out. Sorry if the HTML is a bit of a mess but really it's the second $args array that matters.

<?php $args = array(
                'user_id' => $curauth->ID,
                'number' => 5,
                'status' => 'approve',
                'parent' => 0
                );
  $comments = get_comments($args);
  if ( $comments )
   {
 foreach($comments as $c){

echo '<div id="authorcommentsmain">';
echo '<ul id="authorcomments">';
echo '<li>';
echo '<a id="authorcommentlink" href="'.get_comment_link( $c->comment_ID ).'"> ';
echo get_the_title($c->comment_post_ID);
echo '</a>';
echo "</br>";
echo "<div id='authorcommentslatest'><div id='authorcommentsuserphoto'>";
echo userphoto($c->user_id, '', '', array(id => 'latestcommentsprofile'));
echo "</div>";
echo "<div id='authorcommentexcerpt'> <p>";
echo my_get_comment_excerpt( $c->comment_ID, 80 );
echo "</p></div></div></li>\n";
echo '</ul></div>';



$comment_meta_args2 = array(
                           'status' => 'approve',
                           'parent' => intval($parent_comment_id),
                           'number' => 1,
                           'user_id' => 1,
                           'order' => ASC
                           );
$replies2 = get_comments($comment_meta_args2);

$parent_comment_id = $c->comment_ID;
$comment_meta_args = array(
                           'status' => 'approve',
                           'parent' => intval($parent_comment_id),
                           'number' => 2,

                           'order' => ASC
                           );
$replies = get_comments($comment_meta_args);


if ( $replies2)
{

foreach($replies2 as $r2) {

    echo '<div id="authorcommentsmainSPECIAL">';
echo '<ul id="authorcommentsSPECIAL">';
echo '<li>';
echo "<div id='authorcommentexcerptSPECIAL'>";
echo "<div id='authorcommentsuserphotoSPECIAL'>";
echo userphoto_thumbnail($r2->user_id, '', '', array(id => 'latestcommentsprofileSPECIAL'));
echo "</div>";
echo    "<div id='authorcommentexcerptSPECIALa'>" .  get_comment_author ($r2->comment_ID) . " says... </div> <div id='authorcommentexcerptSPECIALb'>" . get_comment_excerpt( $r2->comment_ID );
echo "</div></div></li>\n";
echo '</ul></div>';

  }
if ( $replies )
{

foreach($replies as $r) {



echo '<div id="authorcommentsmain2">';
echo '<ul id="authorcomments2">';
echo '<li>';
echo "<div id='authorcommentexcerpt2'>";
echo "<div id='authorcommentsuserphoto2'>";
echo userphoto_thumbnail($r->user_id, '', '', array(id => 'latestcommentsprofile2'));
echo "</div>";
echo    "<div id='authorcommentexcerpt2a'>" .  get_comment_author ($r->comment_ID) . " says: </div> <div id='authorcommentexcerpt2b'>" . get_comment_excerpt( $r->comment_ID );
echo "</div></div></li>\n";
echo '</ul></div>';
}   
    }
}
    }




  } else { echo "<p style='text-align: center'> Nothing! </p>\n";} ?>
5
  • I don't know if I understand the question. Do you want to get a list of comments excluding comments that have been made by a specific user? If so, which user? The one you are referring as $curauth->ID?
    – cybmeta
    Commented Dec 12, 2014 at 16:05
  • No, I'd like to exclude user_id->1 in $comment_meta_args Commented Dec 12, 2014 at 16:09
  • I don't understand. If you use get_comments() function you get a list of comments. So, you can include/exclude comments accroding with some criteria, for example you can exclude comments made by user with ID = 1. But you say that you don't want to exlucde comments made by user with ID = 1, you want to exlude user with ID = 1. I'm sorry but I can not imagine how to do that. Can you think again about what you are trying to do and explain it again?
    – cybmeta
    Commented Dec 12, 2014 at 18:26
  • Yes, I mean I'd like to exclude comments made by user with ID = 1, as you said. So it grabs comments by ALL users and excludes comments made by userid =1 Commented Dec 15, 2014 at 9:19
  • I'm sure it's possible to do a global $wpdb SQL query but how would I incorporate intval($parent_comment_id), is that possible? Commented Dec 15, 2014 at 12:03

1 Answer 1

1

Looks like I had to figure this one out myself.

replace $comment_meta_args and $replies with

global $wpdb;
 $comment_meta_args="SELECT * FROM `$wpdb->comments`
 WHERE `comment_approved` = 1
 AND    `comment_parent` = (". intval($parent_comment_id) .")
 AND `user_id` != 1 ORDER BY  comment_date ASC LIMIT 3";

$replies=$wpdb->get_results($comment_meta_args);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.