How to, using PHP scripting or WordPress overwrite all of the posts (permamently, so it takes effect on database) with some static text such as "Content removed."?


Do not run this on a live site until you're tested it on a backup or local installation and confirmed valid results, i won't take any resposibility for lost data, should that occur.

SQL Query

To run from PhpMyAdmin

UPDATE wp_posts SET post_content = 'your_content' WHERE post_type = 'post'

Inside WordPress

To use inside a plugin or your functions file (run once)

global $wpdb;
$my_update_query = $wpdb->get_result( "UPDATE $wpdb->posts SET post_content = 'your_content' WHERE post_type = 'post'" );
  • Might want to add a "WHERE post_type = 'post'" to avoid fudging the data in attachments and custom post types, etc. Just in case! – MathSmath Dec 21 '10 at 17:35
  • Yes of course, and that's exactly why i opened with saying use on a backup or test away from a live site... though i'd have hoped the user would know enough to add applicable where clauses to the query. It can't hurt to add that in though(i'll update the answer). – t31os Dec 21 '10 at 18:05

Another option, if you need further control of the query or the replacement function, is to use more of the WP APIs, like this:

$args = array(
    'post_type' => "post",
    'numberposts' => -1
    // additional arguments

foreach ( get_posts( $args ) as $thispost )
    wp_update_post( array(
        'ID' => $thispost->ID,
        'post_content' => "your new content"

Bear in mind that this is much more resource-intensive than the SQL queries t31os proposed, so use with caution if you're modifying a large number of posts. See also: How to apply content filter permanently?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.