Created
January 11, 2019 11:05
-
-
Save indatawetrust/5721c319292d9cdd1a2bbdc81f8951ff to your computer and use it in GitHub Desktop.
wordpress categories and total courses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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