Last active
January 4, 2016 07:59
-
-
Save nciske/8592264 to your computer and use it in GitHub Desktop.
Cleanup WP post content (e.g. after a migration from another CMS)
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
<?php | |
// Warning: this will overwrite every post in your database | |
// BACKUP FIRST! | |
clean_post_content(); | |
function clean_post_content() { | |
$posts = get_posts(array( | |
'post_type' => array('post'), // or page, or cpt | |
'post_status' => 'publish', // or any, draft, etc | |
'numberposts' => -1, // all posts or number of posts to process | |
)); | |
foreach ($posts as $p) { | |
$p->post_content = wp_filter_kses($p->post_content); | |
wp_update_post($p); | |
echo 'Cleaned post # '.$p->ID.'<br>'; | |
} | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment