Hi,
I need to query a database for a list of posts based on a custom field value. I have found a solution about that here
But how can I get these permalinks from an external database?
I made the DB connection but I cant figure out how to combine the connection with the above’s link code.
If you’re connecting to a remote database, you’ll either have to write a custom SQL query or create a new wpdb instance (unsure of the latter).
Hi @soko
Thanks for the post.
Yes this could be achieved by SQL, you would need something like this:
<?php
$wpdbtest_otherdb = new wpdb('username', 'password', 'shops', 'websitesql.whatever.com');
$wpdbtest_otherdb->show_errors();
$myshops = $wpdbtest_otherdb->get_results("SELECT * FROM shops");
foreach ($myshops as $myshop) {
echo $myshop->shopName . '<br />';
}
?>