Last active
August 22, 2021 15:09
-
-
Save bagerathan/4efa05cf82c03ed8fa8798cbcba5b536 to your computer and use it in GitHub Desktop.
[Useful SQL queries] #wp #sql
This file contains hidden or 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
| /* remove meta field */ | |
| DELETE FROM wp_postmeta WHERE meta_key = 'YourMetaKey'; | |
| /* batch deleted spam comments */ | |
| DELETE FROM wp_comments WHERE wp_comments.comment_approved = 'spam'; | |
| /* batch deleted all unapproved comments */ | |
| DELETE FROM wp_comments WHERE comment_approved = 0; | |
| /* disable comments on older posts */ | |
| UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2016-01-01' AND post_status = 'publish'; | |
| /* remove unwanted shortcodes */ | |
| UPDATE wp_post SET post_content = replace(post_content, '[unusedshortcodes]', '' ); | |
| /* change post type */ | |
| UPDATE wp_posts SET post_type = 'page' WHERE post_type = 'post'; | |
| /* delete all revisions */ | |
| DELETE FROM wp_posts WHERE post_type = "revision"; | |
| /* search and replace post content */ | |
| UPDATE wp_posts SET 'post_content' = REPLACE ('post_content', 'OriginalText', 'NewText'); | |
| /* delete all WooCommerce products */ | |
| DELETE relations.*, taxes.*, terms.* | |
| FROM wp_term_relationships AS relations | |
| INNER JOIN wp_term_taxonomy AS taxes | |
| ON relations.term_taxonomy_id=taxes.term_taxonomy_id | |
| INNER JOIN wp_terms AS terms | |
| ON taxes.term_id=terms.term_id | |
| WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product'); | |
| DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product'); | |
| DELETE FROM wp_posts WHERE post_type = 'product'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment