Switch WordPress database outside WordPress
-
I have two WordPress blogs on the same domain/server – one regular posts the other videos – plus other non-Wordpress pages which have a box with the latest blog posts using this:
<?php require($_SERVER[‘DOCUMENT_ROOT’] . ‘/blog/wp-load.php’); $args = array( ‘cat’ => 5, // Only source posts from a specific category ‘posts_per_page’ => 1 // Specify how many posts you’d like to display ); $latest_posts = new WP_Query( $args ); if ( $latest_posts->have_posts() ) { while ( $latest_posts->have_posts() ) { $latest_posts->the_post(); ?> <span class=”post_title”><?php the_title(); ?></span> ” title=”<?php the_title(); ?>”> <?php if ( has_post_thumbnail() ) { ?> <span class=”post_thumbnail”><?php the_post_thumbnail(); ?></span> <?php } ?> <span class=”post_excerpt”><?php the_excerpt(); ?></span> <? } } wp_reset_postdata(); ?>[Moderator note: per forum guidelines please enclose code in backticks]
All works as I want it. However we now want a second box under the first on the same pages with posts from the other blog (video). As wp-load.php has already been included for the first blog box it gets posts from the wrong blog.
How can I swap the database connection to the settings for the other (video) blog?
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Switch WordPress database outside WordPress’ is closed to new replies.