I'm trying to bulk-create a certain number of blogs:

  $blog_count = 5;
  $site = get_current_site();

  while($blog_count > 0){

    $blog_title = implode(' ', array_slice($words, 0, mt_rand(1, 3)));
    $blog_domain = $blog_path = sanitize_key($blog_title);

    if(domain_exists($site->domain, $site->path.$blog_path, $site->id)) continue;

    $blog_id = wpmu_create_blog($site->domain, $site->path.$blog_path, $blog_title, 0, '', $site->id);

    echo "Created - {$blog_id}";


And I cannot get the paths set up correctly on all blogs. In this case only 2 out of 5 blogs work correctly.

  • $site-domain is "localhost"
  • $site->path.$blog_path is "/wpmutest/thenameoftheblog/"

(this is not a sub-domain install)

When I go and edit them, the "Update siteurl and home as well." option is unchecked on the problematic blogs, and I cannot update it (it doesn't change after I press save). It seems that the database tables are not getting created.

Am I doing something wrong here, or is this a bug?

  • might have something to do with this, but that patch didn't work for me... Sep 11, 2011 at 22:22
  • The ticket got some more traction, just FYI. It's said the issue has been fixed.
    – hakre
    Oct 12, 2011 at 23:08

1 Answer 1


Apparently a global variable is not properly updated. I found a fix based on blackriver's reply here, it's a little ugly but it works:

add_action('switch_blog', 'fix_wpmu_create_blog', 10, 2);
function fix_wpmu_create_blog($new_blog_id, $old_blog_id){
  global $wpdb, $wp_queries;

  if($wp_queries && defined('FIX_WPMU_CREATE_BLOG')){
    $old_pattern = $wpdb->base_prefix.$old_blog_id.'_';
    $new_pattern = $wpdb->base_prefix.$new_blog_id.'_';
    $wp_queries = str_replace($old_pattern, $new_pattern, $wp_queries);
    //echo '<pre>';
    //echo '</pre>';


define('FIX_WPMU_CREATE_BLOG', true);

somewhere in the code that's using this function.

If someone has a better solution please post it so I can accept an answer :)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.