I have read that you can have two wordpress database tables (using different table prefixes) to share the same database.

I understand the concept but does any know of or can anyone provide an outline on the processes involved when using search for example. I would ideally, like to search from one site and be able to get results from both sites (_wp1 posts and _wp2 posts). How would I set this up?

Current setup:

Site one: Free site blog content, 5000 + posts, big database. Search will only return free content (_wp1)

Site two: (new) A premium paid content subscription service featuring new blogs. Search will return new premium content (_wp2) AND the original free content. So is it best to write all posts from the free site and just set whether its premium, or should I separate where the blogs are written? Custom field filters need to work with this (assuming the posts have the same post setup on both).


  • 1
    This doesn't seem to be a coherent question. Are you asking how to have two separate WordPress installs using the same SQL database, or are you asking how to separate free/paid content in the same database? The former is fairly trivial; the latter is probably overly broad. Nov 26, 2012 at 14:23
  • Sorry to be confusing. I currently have free content in one wordpress site. I now have a premium paid site on a subdomain. I want my paid site to search it's own posts but also pull in the posts from the free site. I want the premium site to display the free posts with the premium theme. My question is, what is the best way to achieve this? Sorry if it's quite vague, but I really just need some sort of guidance.
    – zilj
    Nov 26, 2012 at 16:17

1 Answer 1


It is possible to add custom queries to the 2nd site, and pull posts from the first site:

$mydb = new wpdb('root','root','dev1','localhost');
$query_result = $mydb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish'");
if ($query_result) {
    foreach ($query_result as $result) {
        get_template_part( 'content', get_post_format() );
} else {
    echo "<p>Not found</p>" ;

See wpdb and setup_postdata.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.