Hi all,
For boring reasons that are beyond my control, I have to read from a WordPress database from a server that does not have WordPress installed.
I've had some limited success today using the HyperDB class to make this work. In short: it works, but I have to use the exact database table names such as "wp_posts" - ie, using "$wpdb->posts" returns nothing. I'm hoping you guys can help me figure out why that is, like what sort of dependencies I could be missing, etc.
Here is my test code, which outputs the currently published posts as I would expect:
<?php
# WPDB:
require_once '/XXXXX/wpdb.php';
# Do some tests:
$postsQuery = $wpdb->get_results("SELECT ID, post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish'");
if($postsQuery){
echo '<p>Posts found:</p>'."\n";
foreach ($postsQuery as $post) {
echo '<p>#'.$post->ID.': '.$post->post_title.'<p>'."\n";
}
} else {
echo '<p>No posts found.</p>'."\n";
}
?>
In the code above, the "wpdb.php" file sets up the PHP constants that are normally defined in "wp-config.php", and then requires the two PHP files for HyperDB.
The examples in the wpdb class reference use "$wpdb->TABLE_NAME" in place of the actual table name in the SQL queries. If I change the $postsQuery line in my example code above to reflect this (using "$wpdb->posts" instead of "wp_posts"), the final output is instead "No posts found."
Does anyone know why that might be, or what kinds of tests I could run to see where this is failing? Are there dependencies other than the PHP constants defined in "wp-config.php" that I should be including?
Thanks for your time. :)