Created
June 25, 2019 07:17
-
-
Save yanknudtskov/a75b98adb4bc475f296a09698b98a441 to your computer and use it in GitHub Desktop.
An easy way to get all products in WooCommerce which doesn't have a category, using SQL
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
# Gets all product category term IDs | |
SELECT wp_terms.term_id | |
FROM wp_terms | |
LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id | |
WHERE wp_term_taxonomy.taxonomy = 'product_cat' | |
# Use the list of IDs from above into IN ( ) using commaseparation | |
# This will return all the product IDs which are associated to product categories | |
SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN( ) | |
# Use the list of IDs from above into IN ( ) using commaseparation | |
# This will return all the products that are published and NOT found associated with a product category | |
SELECT * FROM wp_posts WHERE post_type = 'product' AND post_status = 'publish' AND ID NOT IN () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment