Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ccurtin/3a8d3906b1ecf1e58b20bac65473102c to your computer and use it in GitHub Desktop.
Save ccurtin/3a8d3906b1ecf1e58b20bac65473102c to your computer and use it in GitHub Desktop.
Delete All Wordpress/WooCommerce Posts/Products Within a Specific Category
# DELETE all posts with category ID of "2906"
delete a,b,c,d
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE e.term_id = 2906
# VIEW all posts with category ID of "2906" (safe/dry run)
SELECT *
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE e.term_id = 2906
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment