Created
September 9, 2016 18:20
-
-
Save pablo-sg-pacheco/dac48c21d3f120df990aea58188ed17d to your computer and use it in GitHub Desktop.
Teste pra fazer uma query no wordpress puxando os posts e os termos
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
#TEST1 | |
SELECT wp_posts.post_title, t.name | |
FROM wp_posts | |
LEFT JOIN wp_term_relationships tr ON tr.object_id=wp_posts.ID | |
LEFT JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id=tr.term_taxonomy_id AND tt.taxonomy='shopping_list_tax' | |
LEFT JOIN wp_terms t ON t.term_id=tt.term_id | |
WHERE 1=1 AND wp_posts.post_type = 'shopping_list_sg' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') | |
ORDER BY wp_posts.post_date DESC | |
#TEST 2 | |
SELECT wp_posts.* FROM wp_posts | |
LEFT JOIN wp_term_relationships tr ON tr.object_id=wp_posts.ID | |
LEFT JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id=tr.term_taxonomy_id AND tt.taxonomy='genre' | |
LEFT JOIN wp_terms t ON t.term_id=tt.term_id | |
WHERE 1=1 AND wp_posts.post_type = 'shopping_list_sg' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC | |
#TEST 3 | |
GROUP_CONCAT(t.name SEPARATOR ', ') AS genres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment