Converting a WP.org Site To WPMU

I have a lot of WordPress sites I manage and I’ve been thinking about converting them to WordPress MU sites to consolidate management. Today I attempted the first one, about.Scriblio.net. There’s no proper way of doing it that I found, but here’s what I did:

  • Create a new site in MU
  • Create the users in the correct order (user ID numbers must match)
  • Replace the posts, postmeta, comments, terms, term_taxonomy, and term_relationship tables with those from the original blog
  • Copy the contents of wp-content/uploads to wp-content/files
  • Update the posts table with the new path (both for regular content and attachments, see below)
  • Hope it all worked

Somebody is likely to say “just export the content in WordPress XML format and import it in the new blog,” but that person doesn’t use permalinks based on post_id. Doing the export/import dance destroys post_id-based permalinks, and that’s a bad thing™.

The MySQL queries to update the posts with the new upload location:

  • for “regular content”
    ```

    UPDATE {new_posts_table} SET post_content = REPLACE(post_content, ’/wp-content/uploads/’, ‘scriblio.net/wp-content/files/’) WHERE post_content LIKE %/uploads/%

              </td>
            </tr>
          </table>
        </div>
    
      * for the attachments <div class="wp_syntax">
          <table>
            <tr>
              <td class="code">
                ```
    <span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #FF00FF;">{</span>new_posts_table<span style="color: #FF00FF;">}</span>
    <span style="color: #990099; font-weight: bold;">SET</span> guid <span style="color: #CC0099;">=</span> <span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">(</span>guid<span style="color: #000033;">,</span> <span style="color: #008000;">'/wp-content/uploads/'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'scriblio.net/wp-content/files/'</span><span style="color: #FF00FF;">)</span>
    <span style="color: #990099; font-weight: bold;">WHERE</span> guid <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>/uploads/<span style="color: #008080; font-weight: bold;">%</span>'</span>
    
          </td>
        </tr>
      </table>
    </div>