Title: Switch WordPress database outside WordPress
Last modified: December 6, 2016

---

# Switch WordPress database outside WordPress

 *  [davideldred](https://wordpress.org/support/users/davideldred/)
 * (@davideldred)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/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](https://codex.wordpress.org/Forum_Welcome#Posting_Code)
   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
    -  This topic was modified 9 years, 5 months ago by [bdbrown](https://wordpress.org/support/users/bdbrown/).

Viewing 1 replies (of 1 total)

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/switch-wordpress-database-outside-wordpress/#post-8524178)
 * I don’t have exactly the answer you want – this isn’t something I’ve seen tried
   before – but this seems like a good use-case for the WordPress REST API, now 
   part of Core since 4.7. Documentation is here: [http://v2.wp-api.org](http://v2.wp-api.org)

Viewing 1 replies (of 1 total)

The topic ‘Switch WordPress database outside WordPress’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/switch-wordpress-database-outside-wordpress/#post-8524178)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
