2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 5-6 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 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
  • Author had a Free File of the Month
  • Has been a member for 5-6 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 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!?

3219 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
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