Forked from zarei-dev/woocommerce_attributes_query.sql
Created
January 17, 2022 12:02
-
-
Save parsafatehi/7ec249d50add685a947a44eca27a6651 to your computer and use it in GitHub Desktop.
woocommerce attributes sql query
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 | |
t.term_id AS 'Attribute Value ID', | |
TRIM('pa_' FROM tt.taxonomy) AS 'Attribute Name', | |
t.name AS 'Attribute Value', | |
COUNT(t.name) as 'num' | |
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_id AND tt.taxonomy LIKE 'pa_%' | |
INNER JOIN wp_terms AS t | |
ON | |
tr.term_taxonomy_id = t.term_id | |
WHERE | |
p.post_type = 'product' AND p.post_status = 'publish' | |
GROUP BY t.term_id, t.name, tt.taxonomy; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment