[wp-hackers] Cloning content from Master site into new sites on a WP Network

Otto otto at ottodestruct.com
Wed Jul 11 19:10:26 UTC 2012


If this is a one-time thing, or something that they're not going to do
a whole lot, then you can use switch_to_blog and restore_current_blog.

Example:

switch_to_blog(1); // id number of the blog
.. do the stuff to get the post data you need here..
restore_current_blog();
.. loop to insert that data as posts or whatever...

The problem with switch_to_blog is that it has a fair amount of
overhead, and so you shouldn't do it too often or unnecessarily.

-Otto


On Wed, Jul 11, 2012 at 1:56 PM, Jesse Friedman
<highfive at jesserfriedman.com> wrote:
> Hello All
>
> What's the best way to grab posts, pages, CPT's from a Master (top level)
> site in a WP Network and clone it into another site?
>
> I've created a page template from wp-signup.php to alter the "Add New Blog"
> form.  Now the form query's all the "Products" custom posts in the Master
> Site and displays them as checkboxes.  The goal here is that when a new
> site is added to the network a potential admin can select the products they
> offer from a Master list of products and that content (currently existing
> in the Master Site) will be duplicated into the new site.
>
> My question is should I be using wp_insert_post().  Since I have the id's
> of all the CPT's in the master site and the ones that the admin has
> selected it'd be easy enough to loop through the info and use
> wp_insert_post to insert the posts into the new site.  The problem is I
> can't seem to define the site id of the new site with wp_insert_post().
>
> thanks for the help
>
> Jesse
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list