2178 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 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_%';
2178 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+10 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!?

3436 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/

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by