Tag Info

Hot answers tagged

6

@G.M.’s idea to cache the check has lead me to the following helper function. I’ve put it into the global namespace to have it available everywhere. The function doesn’t say anything about the blog status, just if it exists and is not marked as deleted. The database query is very fast (0.0001 seconds) and runs just one query per site id, no matter how often ...


4

Unfortunately, the switch_to_blog() method isn't going to work for this purpose. switch_to_blog() is really only a partial switch - it makes some modifications to $wpdb that help with database queries. But it's not a complete switch in the way you might imagine. In particular, dynamic_sidebar() depends on global called $wp_registered_sidebars. This global ...


3

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


3

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


2

You should first read (emphasis mine): The sites in a multisite network are separate, very like the separate blogs at WordPress.com. They are not interconnected like things in other kinds of networks (even though plugins can create various kinds of interconnections between the sites). If you plan on creating sites that are strongly ...


2

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 followed it) significantly affected site performance in some way


2

No, it's retrieving the posts just fine, but you're not storing them anywhere. Here's your code again, with line-by-line documentation: // Set up global variables. Great global $wpdb, $blog_id, $post; // Get a list of blogs in your multisite network $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); // Iterate through your list of ...


1

Make sure you have the exact same sidebars registration code running on both sites during widgets_init. That should populate $wp_registered_sidebars and solve the problem that Boone highlighted. Haven't tried this myself.


1

switch_to_blog(1); to switch to the root (primary) blog and pull post info. restore_current_blog(); to switch back.


1

Ran into the same problem and kind of figured out a solution. What i'm doing is the following: 1.) Whenever something is changed on blog 1's sidebar, save an array of those widgets and their settings as a sitewide transient, that outdates after 24 hours. 2.) On all child-blogs, put some code into sidebar.php that grabs this sitewide transient and displays ...


1

Hook into 'pre_insert_term', $term, $taxonomy and dump the global $blog_id; to see if you're on the right place: function wpse_inspect_blog_id( $term, $taxonomy ) { global $blog_id; var_dump( $blog_id ); exit; } function wpse_hook_inspector_blog_id() { add_filter( 'pre_insert_term', 'wpse_inspect_blog_id' ); } add_action( 'init', ...


1

Edit: You have an extra underscore in your table name, it becomes wp__posts in your case. Better use like how I have shown below :) First, use table names like the following and try var_dump to see if it returns NULL. In case the Post ID doesn't exist, $product will be NULL, which only var_dump can show. $product = $wpdb->get_row("SELECT * FROM ...


1

Short answer but... get_blogaddress_by_name or get_blogaddress_by_id look to me like what you need. Both return the full blog URL.


1

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 first place so, having required that the user saved ...



Only top voted, non community-wiki answers of a minimum length are eligible