Last active
August 29, 2015 13:57
-
-
Save devfreddy/9782562 to your computer and use it in GitHub Desktop.
Wordpress Term/Tax Group by Locations
This file contains 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 parent.name, t.name, COUNT( * ) | |
FROM wp_posts AS p | |
INNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_id | |
INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
INNER JOIN wp_terms AS t ON tt.term_id = t.term_id | |
LEFT OUTER JOIN wp_terms AS parent ON tt.parent = parent.term_id | |
WHERE p.post_type = 'clubfoot_patient' | |
AND tt.taxonomy = 'medrec_locations' | |
AND ( parent.name IN ( 'Rwanda', 'Ethiopia', 'India' ) OR t.name IN ( 'Rwanda', 'Ethiopia', 'India' ) ) | |
GROUP BY parent.name, t.name | |
/** **/ | |
SELECT p.id, | |
parent.name ParentName, | |
t.name Name, | |
tt.taxonomy | |
FROM wp_posts AS p | |
INNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_id | |
INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
INNER JOIN wp_terms AS t ON tt.term_id = t.term_id | |
LEFT OUTER JOIN wp_terms AS parent ON tt.parent = parent.term_id | |
WHERE | |
p.post_type = 'clubfoot_patient' | |
AND tt.taxonomy = 'medrec_locations' | |
AND parent.name in ('Rwanda', 'Ethiopia', 'India') | |
/** **/ | |
SELECT parent.name, | |
COUNT(*) | |
FROM wp_posts AS p | |
INNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_id | |
INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
INNER JOIN wp_terms AS t ON tt.term_id = t.term_id | |
LEFT OUTER JOIN wp_terms AS parent ON tt.parent = parent.term_id | |
WHERE | |
p.post_type = 'clubfoot_patient' | |
AND tt.taxonomy = 'medrec_locations' | |
AND parent.name in ('Rwanda', 'Ethiopia', 'India') | |
GROUP BY parent.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment