// Получаем последние комментарии из этих топиков if($this->getProperty('one_comment_per_thread')){ $ids = array(); $sub_query = $this->modx->newQuery($this->classKey); $sub_query->select(array( "max(id) as id", "thread_id", )); $sub_query->groupby('thread_id'); $s = $sub_query->prepare(); $s->execute(); while($row = $s->fetch(PDO::FETCH_ASSOC)){ $ids[] = $row['id']; } if($ids){ $query->where(array( "id:in" => $ids, )); } }