Wordpress, Multisite second site post also appear on main site

Asked

Viewed 61 times

2

I have a question on the multisites issue of wordpress... 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?

from now on I thank you all.

1 answer

3


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, 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...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.