2024 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 more
revaxarts says

What is the best way to delete all post and pages (etc.) of a wordpress installation to restart with a “fresh” one? I truncate all tables this way but is there any “native” or recommended method?

TRUNCATE TABLE `wp_posts`;
TRUNCATE TABLE `wp_postmeta`;
TRUNCATE TABLE `wp_comments`;
TRUNCATE TABLE `wp_commentmeta`;
TRUNCATE TABLE `wp_links`;
TRUNCATE TABLE `wp_terms`;
TRUNCATE TABLE `wp_term_relationships`;
TRUNCATE TABLE `wp_term_taxonomy`;
DELETE FROM `wp_options` WHERE `wp_options`.`option_name` LIKE '_transient_%';
2024 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Contributed a free file of the month
+8 more
revaxarts says
I’m using this right now
$removed = array();
if($wpdb->query("TRUNCATE TABLE $wpdb->posts")) $removed[] = 'Posts removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->postmeta")) $removed[] = 'Postmeta removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->comments")) $removed[] = 'Comments removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->commentmeta")) $removed[] = 'Commentmeta removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->links")) $removed[] = 'Links removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->terms")) $removed[] = 'Terms removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->term_relationships")) $removed[] = 'Term relationships removed';
if($wpdb->query("TRUNCATE TABLE $wpdb->term_taxonomy")) $removed[] = 'Term Taxonomy removed';
if($wpdb->query("DELETE FROM $wpdb->options WHERE `option_name` LIKE ('_transient_%')")) $removed[] = 'Transients removed';
$wpdb->query("OPTIMIZE TABLE $wpdb->options");

Any suggestions!?

3231 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

well theres http://codex.wordpress.org/Function_Reference/wp_delete_post but it wouldn’t remove all the post just single by id.. is this a function you’re building or you trying to just making it easier for development?

also may want to look at http://wordpress.org/extend/plugins/wordpress-reset/

by
by
by
by
by
by