Wordpress, MultiSite second site post also appear on the main site

2

I have a question on the wordpress multisites question ... I need the posts made on site2 to be seen also on site1, but not the opposite ...

Is there such a native possibility? is there any plugin to do this? or some other way?

Thank you very much.

    
asked by anonymous 08.05.2017 / 21:36

1 answer

3

You can do this using switch_to_blog( $id ) and restore_current_blog() .

Within the theme of site1 you use the functions to fetch the content from site2. switch_to_blog() causes the database queries to be made relative to the site you specify in the $id parameter. When you're finished fetching the information, use restore_current_blog() to return to the site 1 bank.

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
    
10.05.2017 / 13:19