Drupal - Get Node Counts For Each Content Type
Category:
Here is how to retrieve a count of nodes for each content type in a Drupal 6 or 7 site:
SELECT COUNT({node}.nid) AS node_count, {node_type}.type FROM {node} INNER JOIN {node_type} ON {node}.type = {node_type}.type GROUP BY {node_type}.type;
(Note, this isn't the 'correct' way to do this in Drupal 7, we should really use the new Database API Layer, but I'm lazy right now.)
This will give you a table something like this:
node_count | type |
123 | page |
7 | article |
Here is a copy of the SQL query without Drupal's curly brackets:
SELECT COUNT(node.nid) AS node_count, node_type.type FROM node INNER JOIN node_type ON node.type = node_type.type GROUP BY node_type.type;
Comments
sravanthi (not verified)
Mon, 12/02/2013 - 04:53
Permalink
Where should i add this sql
Where should i add this sql query.
I want my output like, the users and the count of articles he has created in the site
tyler
Mon, 12/02/2013 - 10:29
Permalink
You'll need to create a
You'll need to create a custom module, implement hook_menu() to create a page, then place this query in the 'page callback' function. Then you can use something like theme('table', ...); to create a table of user names and their node counts.