Seperating custom post type comments from regular blog posts comments

I have a custom post type (gs_index) with commments enabled, and would like to display a list of recent comments only from that particular post type (outside of the loop)

I would also like to display the standard blog posts’ comments without the comments from the custom post type.

Read More

Here is the code I am currently using

<ul>
  <?php
    $comments = get_comments('number=10&status=approve');
    $true_comment_count = 0;
    foreach($comments as $comment) :
  ?>

  <?php $comment_type = get_comment_type(); ?>
  <?php if($comment_type == 'comment') { ?>  
  <?php $true_comment_count = $true_comment_count +1; ?>  
  <?php $comm_title = get_the_title($comment->comment_post_ID);?>
  <?php $comm_link = get_comment_link($comment->comment_ID);?>
  <?php $comm_comm_temp = get_comment($comment->comment_ID,ARRAY_A);?>
  <?php $comm_content = $comm_comm_temp['comment_content'];?>

    <li>
      <span class="footer_comm_author">
        <?php echo($comment->comment_author)?>
      </span> on 
      <a href="<?php echo($comm_link)?>" title="<?php echo $comm_title?>">
        <?php echo $comm_title?> 
      </a>
    </li> 

  <?php } ?>
  <?php if($true_comment_count == 5) {break;} ?>
  <?php endforeach;?>
</ul>

Related posts

Leave a Reply

2 comments

  1. It’s not well documented, but according to the codex, you can pass a ‘type’ variable in the get_comments function. Give this a shot

    $comments = get_comments('number=10&status=approve&type=YOUR_POST_TYPE');