How to interact with another wordpress install on same database?

I am trying to figure out how I can have two WordPress installations on same database with different prefixes ( wp_ and wp2_ ) and I need them to interact with each other.

For example I have a Blog on one site and a Directory on another site using same database with two wordpress tables (wp and wp2).

Read More

How can i pull the classified listings into the blog site.
like the latest directory listings and etc.

Related posts

1 comment

  1. Reading through the source code for the wpdb class, I see no reason why something like this shouldn’t work:

    $otherdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    $otherdb->prefix = 'wp2_';
    

    And then (if I’m understanding this right) you can use all the existing $wpdb methods and variables. Eg:

    $x = $otherdb->get_results( $sql_query );
    

    (If I’m wrong — or if this is bad practice for reasons I haven’t considered — please feel free to correct me.)

Comments are closed.