Connect to another WP install and grab post based on custom field

The query_posts() inside your database call is being evaluated first, on the current site, and returning an array – which is probably empty, since its not the database you were expecting to be querying. Then that array of posts is being passed to the outer $hbldb->get_results() call, which is giving you your error, because it isn’t a valid MySQL query syntax.

If you want to deal with the raw SQL query on your external database, you would have to write that entire query within your call to get_results()… ie, something like this:

$results = $hbldb->get_results( "SELECT * FROM 
                                {$hbldb->posts} posts 
                                JOIN {$hbldb->postmeta} meta
                                ON meta.post_id = posts.ID
                                WHERE meta.meta_key ='dbt_ffhpost'
                                AND meta.meta_value="on"",
                                ARRAY_A );

*(edited: added ARRAY_A argument to make this query return an array.)*

I think there must be a better way of doing this, but I can’t quite wrap my head around how to to create a new WP_Query object that relates to a secondary wpdb object, or even if that’s possible, so the best help I can give is the raw SQL.

And, once you have these results, you can loop through them like this:

<?php 

if ($results) : 

foreach ($results as $post) :

echo '<h2>'.apply_filters( 'the_title', $post->post_title ).'</h2>';
echo '<h4>'.apply_filters( 'the_author', $post->post_author ).'</h4>';
echo apply_filters( 'the_content', $post->post_content );

endforeach; endif;

?>

Note that getting more advanced data from this second WP install is much harder using this method. I didn’t even deal with getting the permalinks, etc. If you need to get more data out of the other WP install, you might be better off setting up an RSS feed from that site and displaying items from that RSS feed on the first site using a plugin or basic fetch_feed() code.