Last active
December 1, 2023 13:15
-
-
Save devinsays/f7041bb5747007f6612ac5d9c532d08c to your computer and use it in GitHub Desktop.
SQL: Get WooCommerce Product ID, title, SKU, and Image
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 | |
products.id, | |
products.post_title as title, | |
meta3.meta_value as sku, | |
meta2.meta_value as image_url | |
FROM | |
wp_qftw_posts products | |
LEFT JOIN | |
wp_qftw_postmeta meta1 | |
ON ( | |
meta1.post_id = products.id | |
AND meta1.meta_value IS NOT NULL | |
AND meta1.meta_key = "_thumbnail_id" | |
) | |
LEFT JOIN | |
wp_qftw_postmeta meta2 | |
ON ( | |
meta1.meta_value = meta2.post_id | |
AND meta2.meta_key = "_wp_attached_file" | |
AND meta2.meta_value IS NOT NULL | |
) | |
LEFT JOIN | |
wp_qftw_postmeta meta3 | |
ON ( | |
meta3.post_id = products.id | |
AND meta3.meta_key = "_sku" | |
AND meta3.meta_value IS NOT NULL | |
) | |
WHERE | |
products.post_status="publish" | |
AND products.post_type="product" | |
ORDER BY | |
products.post_date DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment