Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Last active April 12, 2016 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbachhuber/d1a97ceab65e7e7a17ba8182cb8c2e00 to your computer and use it in GitHub Desktop.
Save danielbachhuber/d1a97ceab65e7e7a17ba8182cb8c2e00 to your computer and use it in GitHub Desktop.
Empty Posts 2 Posts tables when using wp site empty
<?php
/**
* Requires WP-CLI v0.24.0-alpha or later because it needs https://github.com/wp-cli/wp-cli/pull/2647
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_hook( 'after_invoke:site empty', function(){
global $wpdb;
foreach( array( 'p2p', 'p2pmeta' ) as $table ) {
$table = $wpdb->$table;
$wpdb->query( "TRUNCATE $table" );
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment