Using wp_enqueue_media() with switch_to_blog() issue
Using wp_enqueue_media() with switch_to_blog() issue
Using wp_enqueue_media() with switch_to_blog() issue
get post id by $content (so by post content)
What is the way to share data between sites in a multisite
switch_to_blog( ) content disappears after load
After a bit of debugging, I was able to narrow this down to the following: The menu that I had created to display across each site in the network was comprised of Custom post types that were not registered on any other subsite, only the main site (1). For whatever reason the custom post type … Read more
try this $sites = get_sites(); global $switched; /** @var WP_Site $site */ foreach ($sites as $site) { if ( $site->archived || $site->spam || $site->deleted ) { continue; } switch_to_blog( $site->blog_id ); $all_posts = get_posts(‘category=-3&numberposts=6&orderby=post_name&order=DSC’); ?> <ul> <?php foreach($all_posts as $post) : setup_postdata($post);?> <li> <a href=”https://wordpress.stackexchange.com/questions/354427/<?php echo get_page_link($post->ID); ?>” title=”<?php echo $post->post_title; ?>”><?php echo $post->post_title; ?></a> … Read more
For 4 blogs – most likely no. The problems start to appear when you have tens of thousands of posts+ across many blogs, and you want to do queries like getting the latest 10 posts from the network. You should test this yourself, and see if the use of that function (and the others that … Read more
Who would say the solution would be this simple… After days battling with this, somehow it struck me: “what if we switch_to_blog() inside the media upload iframe?” What if we require the user to save the post before uploading any images? Turns out I had no answer to why we weren’t doing this on the … Read more
switch_to_blog changes values of global variables (as you can see here: https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-includes/ms-blogs.php#L801). It doesn’t matter if you call it in function or not – these variables will get changed. So yes – you always have to call restore_current_blog when you’ve done all you wanted with the switched blog. Otherwise these variables will stay changed (so … Read more
It turns out I was barking up the wrong (or at least a slightly different) tree by using wp_insert_attachment. media_sideload_image managed to pull attachments from other blogs on the same multisite install, copy them to the aggregating blog’s uploads directory, and generate thumbnails, while wp_insert_attachment was doing what it was supposed to, which just happened … Read more