query posts from database with different table prefix

I installed 2 WordPress installations in my site and they share the same database, only, wordpress1 has table prefix of wp1_ and wordpress2 with wp2_ . How can I query the posts from wordpress1(wp1_) to show in the sidebar widget of wordpress2? I can only show posts from wp1_ to wordpress1 (its own table).

Related posts

Leave a Reply

1 comment

  1. It isn’t too hard to pull off — make a copy of the $wpdb object and tinker with it, and wrap calls to the native widget code in that. That is, assuming that the database access credentials are the same. But I wouldn’t recommend going this route at all; it is difficult to maintain, and you really should practice proper separation of the concerns. It just takes one slip-up and database A will happily write all over database B.

    Have you considered using an RSS widget instead? The http calls could be done over loopback and so shouldn’t add much overhead, and the separate databases will remain… separate.