Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Created January 11, 2019 11:05
Show Gist options
  • Save indatawetrust/5721c319292d9cdd1a2bbdc81f8951ff to your computer and use it in GitHub Desktop.
Save indatawetrust/5721c319292d9cdd1a2bbdc81f8951ff to your computer and use it in GitHub Desktop.
wordpress categories and total courses
SELECT t.term_id,
t.name,
t.slug,
count(post.ID) AS total
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON (t.term_id = tt.term_id)
INNER JOIN wp_term_relationships AS tr ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
LEFT JOIN wp_posts post ON (post.ID = tr.object_id)
WHERE tt.taxonomy IN ('course_category')
GROUP BY t.term_id
ORDER BY t.name ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment