Get comments for a given content type

Public

Get comments for a given content type

</> CopyGet raw version
php
  1. function mymodule_get_comment_count_by_node_type($node_type) {
  2. $query = new EntityFieldQuery();
  3. $result = $query->entityCondition('entity_type', 'node')
  4. ->entityCondition('bundle', $node_type, '=')
  5. ->execute();
  6. $nids = array_keys($result['node']);
  7.  
  8. $comments = db_select('comment', 'c')
  9. ->fields('c', array('cid'))
  10. ->condition('nid', $nids, 'IN')
  11. ->execute();
  12. $comments_count = $comments->rowCount();
  13. return $comments_count;
  14. }