如果您想检查某条评论在get\\u comments()查询中是否有回复(子项),这里还有另一种方法。(您可能不希望在get\\u comments()查询中使用birgire的方法,因为您将在另一个get\\u comments()查询中执行get\\u comments()查询。
我的方法是使用WP\\u comment\\u query类的get\\u children()方法:
$args = array(
\'order\' => \'DESC\',
\'status\' => \'approve\',
);
$comments = get_comments( $args );
foreach ( $comments as $comment ) {
$content = $comment->comment_content;
$comment_children = $comment->get_children();
if($comment_children){
//code for comment with children
} else {
//code for comment without children
}
}
?>