Skip to content

Instantly share code, notes, and snippets.

@twopix
Created March 22, 2018 13:54
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 twopix/fce56710f65695627c55a3656987c2d5 to your computer and use it in GitHub Desktop.
Save twopix/fce56710f65695627c55a3656987c2d5 to your computer and use it in GitHub Desktop.
woocommerce get products with categories
SELECT p.id, p.post_title, p.post_name, p.guid, t.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN `wp_posts` AS p ON p.ID = tr.object_id
WHERE tt.taxonomy IN ('product_cat') and p.post_status = 'publish'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment