I want to connect my Wordpress website 1 to database from Wordpress website 2.
Here is my code:
<?php
$myotherdatabase = new wpdb("username","password","databasename","localhost");
$motscles = "abri";
$query = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = 'nom' AND MATCH (`meta_value`) AGAINST ('" . $motscles . "' IN BOOLEAN MODE)";
$result = $myotherdatabase -> get_results($query, ARRAY_A);
foreach ($result as $post) {
$pids .= $post['post_id'] . ",";// ARRAY_A
}
echo $pids;
?>
The result is empty. If I run the same query directly on Wordpress website 2, it works.
Therre is something wrong in my code? Or do you think the problem may come from hosting?
Thank you
EDIT: The problem came from the hosting. There is a restriction, I can not connect to the website 2 database from website 1.