I am trying to add the most recent post from another WordPress database (on the same server in all actuality), but am getting the following error:
Fatal error: Call to undefined method wpdb::query_posts() in /var/www/site/wp-content/themes/custom/footer.php on line 68
Here is the code:
<!-- .entry-content -->
<?php
$originaldb = new wpdb('username', 'password', 'db', 'localhost');
$originaldb->query_posts( 'posts_per_page=1' );
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<header class="entry-header">
<div class="entry-meta">
<?php echo '<span class="entry-day">'.get_the_date('j').'</span><br><span class="entry-month">'.get_the_date('M').'</span>'; ?>
</div>
<div class="title-box">
<h2 class="blog-title"><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h2>
<?php echo '<a href="'.get_author_posts_url( get_the_author_meta( 'ID' ) ).'">' . the_author() . '</a>'; ?>
</div>
<div class="clear"></div>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<?php endwhile; else: ?>
Testing has failed
<?php endif; ?>
The WordPress wpdb class is a little different than the normal way of querying in that you run “vanilla” database queries.
You can see documentation on the wpdb class on the WordPress docs: http://codex.wordpress.org/Class_Reference/wpdb#Run_Any_Query_on_the_Database
Also, in regard to your code, you should be able to change the line here:
To something like this:
This will provide you with an array of posts that you can then process with a loop: