I have a WordPress network setup, with a parent site and a few other child sites within it. I have a custom plugin that saves content (images & posts) to a list for each user on my parent site. I also have a custom admin menu that reveals the image list via a user dropdown on my main site. I have shortcode on my parent site that reveals a user's favorite image list by user_id.

What I'm trying to accomplish is to change the code of this custom plugin so that the lists appear on the child site/subsite via the shortcode used on the parent site. I imagine that the site_id needs to be passed through this shortcode to make it possible. I also have the custom admin menu on my subsite with the user dropdown, however, the images do not appear when I click to see those favorites.

Now I'll preface this and say I'm not an experienced programmer but my research leads me to believe that I need to modify the code that controls the menu so it can pull the content (i.e. Media library images/attachments/attachment URLs for that post ID) from the main site to the subsites and add a shortcode and function that makes the parameter for site_id possible.

Does anyone know what query/code/function that I would use retrieve this content from the main site to the subsite so that the image lists would appear in a shortcode form and within my admin menu?

I've already tried plugins that allow you to sync the Media Library but they don't work for what I'm trying to accomplishs

If you need examples of what is already established, such as current codes, shortcodes and images, I'd be happy to oblige.

  • you can use the function switch_to_blog and after you search for data as you were on the parent site.
    – Kaperto
    Commented Jan 5, 2020 at 9:14
  • So I would use <?php global $switched; switch_to_blog(5); ?>//CODE HERE//<?php restore_current_blog(); ?>? Do I need to repeat this code or edit the existing code?
    – haltek18
    Commented Jan 5, 2020 at 23:54
  • This is the probably the closest topic I could find: wordpress.stackexchange.com/questions/77816/… except I’m trying to use a short code and admin menu to fetch all the images from the media library of the parent site to the child site. Do I need to use the switch_to_blog function more than once, one for the parent site and one for the child site, or use a universal code to cover them all like in the blog topic? How can I pass the site_id or blog_id through my current shortcode so the content shows on the subsite?
    – haltek18
    Commented Jan 6, 2020 at 4:48


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.