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?


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.


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

1 Answer 1


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


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

  • 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?
    – zilj
    Oct 24, 2012 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.
    – zilj
    Oct 24, 2012 at 11:02
  • 1
    i added some more details on the answer Oct 24, 2012 at 11:05
  • I have some further queries here. Can I use this method in a search. I want to make all posts on the public site searchable from within the private subdomain. I'm using wp_query, how would this tie in. I'll be testing this myself in the mean time. Thanks
    – zilj
    Nov 13, 2012 at 9:51
  • 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.
    – zilj
    Nov 13, 2012 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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