WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

Here is the code I am currently using

    $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'];?>

      <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?> 

  <?php } ?>
  <?php if($true_comment_count == 5) {break;} ?>
  <?php endforeach;?>
share|improve this question
Can you add the code where you register your custom post type? This would be helpful. – hakre Nov 23 '10 at 23:49

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');
share|improve this answer
type is for the type of comment, like normal (empty), pingback or trackback. So it will not select based on the post type the comment is attached to. – Jan Fabry Nov 25 '10 at 20:28
my mistake. dang ambiguous phrasing :) – Norcross Nov 27 '10 at 0:39

What you try to achieve is a missing feature with the get_comments() function in WordPress. So it is basically not possible to get comments by post-type with the get_comments() function so far.

The related ticket is: Ticket #12904 - get_comments(): Enable post_status, post_type

You will need another function that is returning the data you are looking for. Probably you need to write one on your own.

share|improve this answer

protected by Community May 5 '14 at 10:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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