Code for deleting all wordpress database

In this post I share how to delete all the posts, comments, tags, and such with a wordpress site.  To delete the proper data from the database you need to know which data is connected and how.  wordpress.org does a great job of describing this in full detail but you can basically see the connection and get through the code below without it.  The following script could take a wordpress site like http://privateschoolsreviews.com  and delete the entire site except for the theme and settings.  It would be blank slate to start over essentially.

The goal is to clean the data from the following tables:

  •  wp_posts
  • wp_term_relationships
  •  wp_term_taxonomy
  • wp_terms

The following code is slightly incomplete but a little modification would have it up and running.

return(mysql_connect(MYSQL_ADDRESS, MYSQL_USERNAME, MYSQL_PASSWORD));
}
$mysql_connect = connect_to_database();
mysql_select_db(‘table’, $mysql_connect);

# Execute SQL command
$sql=”TRUNCATE TABLE wp_posts”;//e_state =’NC’
$result = mysql_query($sql, $mysql_connect);
echo “posts”.mysql_error();

$sql=”TRUNCATE TABLE wp_terms”;//e_state =’NC’
$result = mysql_query($sql, $mysql_connect);
echo “terms”.mysql_error();

$sql=”TRUNCATE TABLE wp_term_relationships”;//e_state =’NC’
$result = mysql_query($sql, $mysql_connect);
echo “terms”.mysql_error();

$sql=”TRUNCATE TABLE wp_term_taxonomy”;//e_state =’NC’
$result = mysql_query($sql, $mysql_connect);
echo “posts”.mysql_error();

$sql=”TRUNCATE TABLE wp_posts”;//e_state =’NC’
$result = mysql_query($sql, $mysql_connect);
echo mysql_error();

$sql=”TRUNCATE TABLE wp_posts”;//e_state =’NC’
$result = mysql_query($sql, $mysql_connect);
echo mysql_error();

TRUNCATE TABLE simply removes all the rows from the tables without deleting the table .  The structure remains but the information that was saved has been removed.  You should make a backup of your entire database because this is not reversible.

 

Comments Off on Code for deleting all wordpress database

Filed under Uncategorized

Comments are closed.