Merging multiple wp_query objects

If you just need the posts of each WP_Query object, you can do do something like this: <?php // fetch blogs here $all_posts = array() foreach($blogs as $b) { switch_to_blog($b->blog_id); $query = new WP_Query(/* your args here */); if($query->have_posts()) $all_posts = array_merge($all_posts, $query->posts); // posts are stored in the `posts` property restore_current_blog(); // FYI: this … Read more

How to consolidate all sitemaps in a multisite network?

WordPress multisite subdomains or suddirectories? I’m not sure if you’re getting the two confused. Multisite subdomains are basically fake subdomains that simply have a CNAME or A-Name record added in the DNS records. That said, and I believe one responder said this, you just need a sitemap for the root domain, and then you’ll have … Read more

How would I use pre_get_posts to query another site for posts in my multisite network?

OK so for reference I ended up actually using switch_to_blog() and restore_current_blog(). I found no references whatever for querying multiple tables (except writing my own JOIN-statements) when followed the source code for the action pre_get_posts. A lot of advice was given to skip restore_current_blog() to save CPU-cycles but when I checked the source code for … Read more

Removing My Sites menu from Admin

You can use remove_submenu_page to remove it. Note that it doesn’t prevent visiting that page if you manually enter the URL. function adjust_the_wp_menu() { $page = remove_submenu_page( ‘index.php’, ‘my-sites.php’ ); } add_action( ‘admin_menu’, ‘adjust_the_wp_menu’, 999 ); Based on the example from remove_submenu_page Codex page.

WordPress Multisite with NGINX, subfolders, and FROM a subfolder

Actually, I solved it thanks to this reference: https://rtcamp.com/wordpress-nginx/tutorials/multisite/subdirectories/in-a-subdirectory/ With the root directory of the installation being “labs” in my case, the final nginx configuration file looks like: # You may add here your # server { # … # } # statements for each of your virtual hosts to this file ## # You … Read more

How do I share plugin settings across WordPress network?

The generic way to do it, is by using the pre_option_{option} https://codex.wordpress.org/Plugin_API/Filter_Reference/pre_option_(option_name) filter to override the “local” settings and use the value being stored in your “main” sub site. something like add_filter( ‘pre_option_the_plugin_option_name’, function () { // Code assumes that “blog” 1 is the main one in which the relevant settings are stored. if (get_current_blog_id() … Read more