Is it possible to search another page’s DB?
-
Long story short:
Several individual pages (no multisite, the pages belong to different companies) are supposed to be able to allow user to search through content of yet another page (posts and events manager events).
Obvious solution: Link to the central content page, done. But customer would like user to search without leaving the current page – or at least the illusion.
– iframe is no solution (sadly, ’cause it works fine otherwise), because IPhones6 and below don’t like no Iframes and workarounds don’t work, I assume due to running javascripts
– sharing the content on a non-multisite setup: So far I could only find one Plugin allowing to share content on not-multisite pages – https://distributorplugin.com/ – but that’s still in development and not yet ready for a life setting. Too many bugs and glitches yet to be solved.
– final idea: connecting to the central page’s database and search right there, only I’ve not yet really worked with databases before and don’t get it to work so far.
I am using this script:
global $wpdb; $thedb = $wpdb; $mydb = new wpdb('*****MyUserName','*****MyPassword','*****MyDatabase','*****MyHost'); $wpdb = $mydb; print_r($wpdb); $result = $wpdb->get_results ( " SELECT * FROM $wpdb->posts WHERE post_type = 'post' " ); foreach ( $result as $page ) { echo $page->ID.'<br/>'; echo $page->post_title.'<br/>'; } $wpdb = $thedb;
But I don’t get any results. But the print_r($wpdb) tells me: “[has_connected:wpdb:private] => 1”
– when I change the password (for example) I instead get:
“[has_connected:wpdb:private] =>
[error] => WP_Error Object
(
[errors] => Array
(
[db_connect_fail] => Array
(
[0] =><h1>Fehler (….)”That tells me that I do indeed get connected to the remote database, but why are there no results? I DO get results if I run the get_results on the local Database, so the script is fine.
Any ideas? Am I missing something?
- The topic ‘Is it possible to search another page’s DB?’ is closed to new replies.