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?
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
Though this will fail in some wordpress functions & i would recommend sticking with the direct query approach