WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

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.