Skip to content

Instantly share code, notes, and snippets.

@nciske
Last active January 4, 2016 07:59
Show Gist options
  • Save nciske/8592264 to your computer and use it in GitHub Desktop.
Save nciske/8592264 to your computer and use it in GitHub Desktop.
Cleanup WP post content (e.g. after a migration from another CMS)
<?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