Created
February 24, 2019 13:47
-
-
Save mustafauysal/458fa5e7abba65a5ef29923faf2ed7a0 to your computer and use it in GitHub Desktop.
HyperDB multisite example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$wpdb->add_database( array( | |
'host' => 'global.db.example.com', | |
'user' => 'globaluser', | |
'password' => 'globalpassword', | |
'name' => 'globaldb', | |
) ); | |
$wpdb->add_database( array( | |
'host' => 'blog.db.example.com', | |
'user' => 'bloguser', | |
'password' => 'blogpassword', | |
'name' => 'blogdb', | |
'dataset' => 'blog', | |
) ); | |
$wpdb->add_callback( 'my_db_callback' ); | |
// Multisite blog tables are "{$base_prefix}{$blog_id}_*" | |
function my_db_callback( $query, $wpdb ) { | |
if ( preg_match("/^{$wpdb->base_prefix}\d+_/i", $wpdb->table) ) { | |
return 'blog'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment