I want to fetch some post from another wordpress site which is hosted in the same server. How can I fetch those post?
Is multiple database connection is possible in wordpress?
I want to fetch some post from another wordpress site which is hosted in the same server. How can I fetch those post?
Is multiple database connection is possible in wordpress?
You must be logged in to post a comment.
It is possible but you must manually create a new instance of the
wpdb
class with right settings for your other database.Quote from the wpdb Codex page:
You can use HyperDB: https://wordpress.org/plugins/hyperdb/
It allows multiple databases, also read/write replicas or master / slave.
1) Download class db at link: https://codeshack.io/super-fast-php-mysql-database-class/
– rename class db = db_custom
2) …/themes/theme-name/functions.php
$dbhost = ‘db_ip’; // 127.0.0.1
$dbuser = ‘db_user’; // input database username
$dbpass = ‘db_user_password’; // input your database password
$dbname = ‘db_user_name’; // input your datatabase name
$db_watch = new db_custom($dbhost, $dbuser, $dbpass, $dbname);
$sql = “SELECT * FROM products LIMIT 0,2”;
$results = $db_watch->query($sql)->fetchAll();
print_r($results);
I have tested my website WordPress it’s working well