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've searched already and couldn't find anything tailored to my specific problem, apologies if it has already been asked though.

I have a public Wordpress install and a members only one on a subdomain. The reason for this is that they are both very different sites in terms of functionality so creating members only posts in the main site is not an option. On the subdomain new premium content will be added, but I also need to pull in the posts from the public site.

I've looked into feed urls but because I've implemented quite a specific search customisation on the subdomain I need these posts to be searchable. For example I have an additional posts plugin 'post countries' showing a country associated with the post. Is this still something the feed url would be able to handle, or are there any other alternatives?

Thanks

EDIT This is the way my current private search is setup, I've just pasted in the relevant code.

$args = array(
'post_type' => 'post', 
'show_posts' => '10', 
'paged' => $paged
);

$the_query = new WP_Query($args); 

<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
    // The output

In my own sites private db results are stored in $the_query and public site results are stored in $allsearch, which would mean I should add the following and make my loop vanilla.

$the_query->posts=array_merge($the_query->posts,$allsearch);
$the_query->post_count=count($the_query->posts);

Does that sound right, it's not pulling in any posts from public site?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

if it's the same database, you can write the query easily using the global $wpdb variable. If it's a separate database, create another instance of wordpress wpdb class & write the queries to it $wpdb2 = new wpdb( $user, $pass, $db, $host );

In any case, you'll need to know the database tables prefix

UPDATE

You can do it either way, either make the public site to insert the data to both databases or make the subdomain pick the data from both it's own database & public database. Let's say you want the 2nd approach

In this case you don't want the public server to do anything, so let's put it aside. Now in the subdomain's template file, you'll already have some code. There you will create a new instance of the wpdb class using the code above with the database details of the public server. Then you'll write a query to the public database using this object. Check out the codex for details on how to do that

If you want to take the first approach, then also you'll do it similarly except that the code is added to the public page's code

Also you can do something like this to use wordpress functions

global $wpdb;
$temp = $wpdb;
$wpdb = new wpdb( $user, $pass, $db, $host );
// make the query here
$wpdb = $temp;

Though this will fail in some wordpress functions & i would recommend sticking with the direct query approach

share|improve this answer
    
Sorry I didn't make that clear, it is a separate db. So does that mean that whenever a post is submitted to the live site, it updates it's own db and then also the subdomain db? To be honest i'm not sure what the best method for this would be? –  Graeme Oct 24 '12 at 10:47
    
I think I need to go back to the drawing board on this one. Thanks for the second instance of wpdb though, that's planted some ideas in my head. –  Graeme Oct 24 '12 at 11:02
1  
i added some more details on the answer –  Mridul Aggarwal Oct 24 '12 at 11:05
    
Excellent, that helps greatly. Thanks again –  Graeme Oct 24 '12 at 13:04
1  
Hm, sounds very logical! Yes I was looking at all options people had tried, I'd prefer to use this method you have outlined. I'll give it a go now, I may have further questions, hope that's ok. –  Graeme Nov 13 '12 at 10:52
show 5 more comments

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.