Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Happy new year everyone.

I've been struggling with this one for a while. I need to get the latest comment from a custom post type, but ignore any child comments i.e. only look at comments with a depth of 1.

I can get the latest comment from a custom post type using:

$args = array(
    'post_type' => 'custom-post-type',
    'number' => '1',
    'orderby' => 'date',
    'order' => 'DESC'
  );

$comments = get_comments($args);
foreach($comments as $comment) :
    echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;

However, it doesn't take into account the depth requirement. Any ideas how I can achieve this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

use the "parent" parameter as 0.

$args = array(
    'parent'=>0    
    'post_type' => 'custom-post-type',
    'number' => '1',
    'orderby' => 'date',
    'order' => 'DESC'
  );

$comments = get_comments($args);
foreach($comments as $comment) :
    echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
share|improve this answer
    
Thanks Rajeev, that's perfect! –  Chris Jan 1 '13 at 15:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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