Skip to content

Instantly share code, notes, and snippets.

@matdave
Last active September 22, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matdave/1ab01922d3997b4e90195296cbdccf6f to your computer and use it in GitHub Desktop.
Save matdave/1ab01922d3997b4e90195296cbdccf6f to your computer and use it in GitHub Desktop.
MODX count number of times a template is used
SELECT a.id, a.templatename, COUNT(b.id) as resources FROM modx_site_templates AS a
LEFT JOIN modx_site_content AS b ON a.id = b.template AND b.published = 1 AND b.deleted = 0
WHERE b.id IS NOT NULL
GROUP BY a.id;
SELECT a.id, a.type, a.name, COUNT(c.id) FROM modx_site_tmplvars a
LEFT JOIN modx_site_tmplvar_contentvalues b ON a.id = b.tmplvarid
LEFT JOIN modx_site_content c ON b.contentid = c.id AND c.published = 1 AND c.deleted = 0
WHERE c.id IS NOT NULL
GROUP BY a.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment