Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Last active June 30, 2020 21:39
Show Gist options
  • Save cesarmiquel/8d04d81cedfd4b6157713975ea99b0ca to your computer and use it in GitHub Desktop.
Save cesarmiquel/8d04d81cedfd4b6157713975ea99b0ca to your computer and use it in GitHub Desktop.
Count number of nodes with a particular term id for Drupal 8.x
select
ti.tid
, ttfd.name
, count(1) as count
from
taxonomy_index ti join node n on n.nid = ti.nid
, taxonomy_term_data td
, taxonomy_term_field_data ttfd
where
td.tid = ti.tid
and td.vid = 'tags'
and ttfd.tid = ti.tid
group by
ti.tid, ttfd.name
order by
count desc
limit 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment