Skip to content

Instantly share code, notes, and snippets.

@ldhertert
Created February 14, 2011 21:25
Show Gist options
  • Save ldhertert/826580 to your computer and use it in GitHub Desktop.
Save ldhertert/826580 to your computer and use it in GitHub Desktop.
SELECT *
FROM wp_posts
LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy tax_type ON(wp_term_relationships.term_taxonomy_id = tax_type.term_taxonomy_id)
LEFT JOIN wp_term_taxonomy tax_client ON(wp_term_relationships.term_taxonomy_id = tax_client.term_taxonomy_id)
LEFT JOIN wp_terms terms_type ON(tax_type.term_id = terms_type.term_id)
LEFT JOIN wp_terms terms_client ON(tax_client.term_id = terms_client.term_id)
WHERE wp_posts.post_type = 'portfolio'
AND wp_posts.post_status = 'publish'
AND tax_type.taxonomy = 'type'
AND tax_client.taxonomy = 'client'
AND terms_type.slug = 'web'
AND terms_client.slug = 'microsoft'
ORDER BY wp_posts.post_date DESC
@ldhertert
Copy link
Author

this works:

SELECT *
FROM wp_posts
LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy tax_type ON(wp_term_relationships.term_taxonomy_id = tax_type.term_taxonomy_id)
LEFT JOIN wp_terms terms_type ON(tax_type.term_id = terms_type.term_id)
WHERE wp_posts.post_type = 'portfolio'
AND wp_posts.post_status = 'publish'
AND tax_type.taxonomy = 'type'
AND terms_type.slug = 'web'
ORDER BY wp_posts.post_date DESC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment