Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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).

Thanks

share|improve this question
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. –  Chip Bennett Nov 26 '12 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. –  Graeme Nov 26 '12 at 16:17
add comment

1 Answer 1

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

<?php
$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) {
        setup_postdata($result);
        get_template_part( 'content', get_post_format() );
    }
} else {
    echo "<p>Not found</p>" ;
}
?>

See wpdb and setup_postdata.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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