Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Created September 9, 2016 18:20
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 pablo-sg-pacheco/dac48c21d3f120df990aea58188ed17d to your computer and use it in GitHub Desktop.
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
#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