Integrating blogs between to separate WordPress websites

Jeremy Leys
Jeremy Leys used Ask the Experts™
on
Hi

The UK office and the rest of the world have a WordPress multi-site instance they share.

The Australia and New Zealand Offices want to share there own separate WordPress multi-site but they want to integrate their blog with the UK and rest of the world site.

I would like a point in the right direction for the best way to achieve this any recommendations are welcome and much appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
James RodgersWeb Applications Developer

Commented:
ok,  just to clarify....

the anz office want to integrate their blog with the rest of the world offices.
Are you meaning show the uk/can/den (for example) blogs on the anz site? or you want the anz office blogs on the uk/can/den sites?
Web Applications Developer
Commented:
quick and dirty

to pull form other blogs to the ANZ site you need to do something along the lines of

// get thecurrent blog id, needed later
$original_blog_id = get_current_blog_id(); 

// get the blog you want to pull from
// https://codex.wordpress.org/Function_Reference/get_blog_id_from_url
$blog_id = get_blog_id_from_url( 'www.domain-3.uk.com' );

switch_to_blog($blog_id); // this function neeeds an int, the blog id you want to interact with

then use
//https://codex.wordpress.org/Template_Tags/get_posts
$latest_posts = get_posts($args);
or
// https://codex.wordpress.org/Function_Reference/wp_get_recent_posts
$latest_posts = wp_get_recent_posts($args );

and process though a loop routine to output

//
// !!!!IMPORTANT!!!!
//
// switch back to your original blog !!!!!!
switch_to_blog($original_blog_id);

Open in new window



to get a listing of posts
you may want to gather all the posts from the different blogs into an array and sort them based on date posted before displaying them
also, if you are doing multiple sites, you just make an array of domains  and loop over it

$domains = array('www.domain-1.com', 'www.domain-2.com','www.domain-3.uk.com','www.domain-4.ca','www.domain-5.com');

foreach($domains as $domain){
	$blog_id = get_blog_id_from_url( $domain );
	// etc...
}

Open in new window

Jeremy LeysTechnical Lead

Author

Commented:
Thank you works like a charm
Jeremy LeysTechnical Lead

Author

Commented:
Thank you this solved my problem

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial