You can do it using switch_to_blog( $id )
and restore_current_blog()
.
Within the theme of site1 you use the functions to search the content of site2. switch_to_blog()
causes the database queries to be made relative to the website you specify in the parameter $id
. When you’re done fetching information, use restore_current_blog()
to return to the bank of the site 1.
Ex.:
$posts = new WP_Query(); // retorna os posts do site 1
switch_to_blog(2)
$posts = new WP_Query(); // retorna os posts do site 2
restore_current_blog();
$posts = new WP_Query(); // retorna os posts do site 1
where exactly add this code
– Jefferson Mello Olynyki
@Jefferson, this is the Milhão question :) Add the code to any template (https://developer.wordpress.org/themes/template-files-section/page-template-files/) or to a Widget code, or to a Shortcode... there are several possibilities. If you’re not a programmer, then there’s another 500...
– brasofilo