0

How do I only get the first level of comments in get_comments() or WP_Comment_Query? I want to query the comments which have 'comment_parent' => 0, and exclude all the child comments.

    $args = array(
        'number'      => 10,
        'order'       => 'DESC',
        'status'      => 'approve',
        'meta_key'    => 'comment_parent',
        'meta_value'  => 0
    );

    $comments = get_comments( $args );
3

This should do the trick, I guess:

$args = array(
    'number'      => 10,
    'order'       => 'DESC',
    'status'      => 'approve',
    'parent'      => 0
);

$comments = get_comments( $args );

You can find full list of arguments in Codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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