Someone asked how he could delete all the transients from a WordPress multisite, as I wrote the code for him, thought to share it here for everyone 🙂
[php]
if ( is_multisite() ) {
global $wpdb;
$all_sites = $wpdb->get_results( "SELECT * FROM $wpdb->blogs" );
if ( $all_sites ) {
foreach ($all_sites as $site) {
$wpdb->set_blog_id( $site->blog_id );
$wpdb->query( "DELETE FROM `{$wpdb->prefix}options` WHERE `option_name` LIKE (‘_transient_%’)" );
}
}
}
[/php]
Greetings, Thank you for the code. It works perfect. I added a couple more conditions to get rid of the new “nextgen gallery” crap.
Cheerz
get_results( "SELECT * FROM $wpdb->blogs" );
if ( $all_sites ) {
foreach ($all_sites as $site) {
$wpdb->set_blog_id( $site->blog_id );
$wpdb->query( "
DELETE FROM `{$wpdb->prefix}options`
WHERE `option_name` LIKE ('_transient_%')
or `option_name` LIKE ('_site\_transient\_%')
or `option_name` LIKE ('displayed\_galleries\_%')
" );
}
}
}
?>