Title: Change Database Prefix While in Loop
Last modified: August 20, 2016

---

# Change Database Prefix While in Loop

 *  [SpidermanPuddin](https://wordpress.org/support/users/spidermanpuddin/)
 * (@spidermanpuddin)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/change-database-prefix-while-in-loop/)
 * I have 2 wordpress websites running off the same database, but each with a different
   prefix. I need to be able to query from site1.com while using site2.com
 * Something like this:
 *     ```
       <?php get_header(); ?>
   
       //Switch to 'pre1_'
   
       // The Query
       query_posts( $args );
   
       // The Loop
       while ( have_posts() ) : the_post();
       	echo '<li>';
       	the_title();
       	echo '</li>';
       endwhile;
   
       // Reset Query
       wp_reset_query();
   
       //Switch back to 'pre_2'
   
       <?php get_sidebar(); ?>
       <?php get_footer(); ?>
       ```
   

The topic ‘Change Database Prefix While in Loop’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [SpidermanPuddin](https://wordpress.org/support/users/spidermanpuddin/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/change-database-prefix-while-in-loop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
