If you regularly work with many different projects in website development, especially the projects have the similar custom fields, this post will be useful for you. This guide will bring you an easy way to copy meta boxes and custom fields from one site to others with our Meta Box Builder.

Meta Box has an extension named Meta Box Builder, which helps you create custom fields in the blink of an eye by drag and drop the fields flexibly. It also lets you configure those fields easily on its UI without touching a single line of code. It is perfect for people even who don’t know any code whatsoever.

However, we don’t talk about that advantage of Meta Box Builder in this post. That is not our principal today. We are going to show another feature of it which helps you clone custom fields from a site to another in a simple way.

Benefits of cloning meta boxes and custom fields among sites

Actually, cloning is copying the code of the meta boxes / custom fields group created in a site, then embedding it into another site. That gives you the same functionality of these meta boxes and custom fields on the embedded site without installing any extension of Meta Box.

There are some benefits of cloning which you definitely are interested in:

  • It helps your embedded website operate with the adequacy of necessary custom fields and its configuration, but with much faster speed because of not installing any plugin for these custom fields beyond our ultra lightweight Meta Box Framework.
  • You only need to create a series of custom fields on local with an adequate configuration as you want. Then embed code of the needed fields in the target sites. That ensures that all of the fields which you import into the sites have the same settings. Of course, then you may not worry about having the same request for the same fields but configurations are different among projects. You also stop the memory of how you configure fields escapes you, whether it has the error or not.
  • It may not waste time anymore in the fields configuration with the complex attributions or conditions. You only do once, and clone to the sites you need. That’ll save a lot of times.
Please note that cloning meta boxes among sites is different to cloning a custom field inside a meta box. Learn more about cloning a custom field.

Now, let’s figure out how to clone codes by Meta Box Builder.

Requirements:

In case you bought our Developer Bundle or Lifetime Bundle, you only need to install Meta Box AIO only because it has full of necessary plugins and extensions.

Creating meta boxes and custom fields

Create the meta boxes and custom fields inside through the UI of Meta Box Builder. Remember completely configuring all the fields.

In there, you can also use concurrently the other extensions of Meta Box to configure your custom fields as you want, ex: Meta Box Group, Meta Box Conditional Logic, Meta Box Geolocation, etc.

For example, I am trying to create the fields as below image:

Create meta box and custom fields by Meta Box Builder

Also, don’t forget the configuration in the options area:

Configure custom meta box & custom fields by Meta Box Builder

Combining with setting up custom fields by Meta Box Conditional Logic:

configure meta box and custom fields with MB Conditional logic

Learn more about how to create custom fields with Meta Box Builder here.

Make sure that you published those fields, and those fields displayed as you want.

Meta box and custom fields display after configure
The custom fields display in backend after configuring

Exporting code of the custom fields

After publishing field group which you created, in the editing interface of the field group, you’ll see a tab “Code”. Click it, then you see the code of field group as below image:

export code of custom fields group by Meta Box Builder

You can manually copy that code to export it or take your mouse hover over the code, then button “Copy” appears to help you copy all of it quickly.

copy code of custom fields group by Meta Box Builder

Pay attention to this code of a field group (as meta box) that you created. In case you need cloning an individual field only, you may create the corresponding meta boxes containing each needed field.

Embed code of field group in the targeted website

Open file function.php in the theme of the website which needs to embed code, then add the code to that file.

Function.php file in theme to add code of custom field
File function.php in the folder containing the theme
Add copied code of meta box & custom fields into the file function.php
Add copied code into the file function.php

Remarks:

  1. The targeted website doesn’t install Meta Box Builder but must install Meta Box Framework to ensure that the embedded code can operate.
  2. In case the target is the original website used to create fields, let’s deactivate Meta Box Builder on this site before embedding its code.
  3. If there has been the other code embedded in the file function.php and it has the same ID with the new code, only the last one is accepted.
  4. You can embed code of many different field groups in one site but must ensure that ID of each field group differs from others then all of the field groups can operate. If the field groups’ IDs is iterated, the last one will be prioritized as the 3rd remark point.
ID of meta box and custom fields group is iterated
The ID of the field group is iterated

Finally, after adding code in sites, added field group is going to operate on the new site similar to the initial site without any hassle. The custom meta box and custom fields also display the same as the original site:

Meta box and custom fields display after configure

Conclusion

Do you see that it is simple? We have done it in the blink of an eye as the other features of Meta Box Builder. Now you don't have to rebuild the custom field groups on the other websites. All you need to do is building once, then export and copy to the other websites. It's pretty simple and fast. We hope with this tutorial, you’ll save a lot of time and effort in future projects.

2 thoughts on “How to Easily Copy Custom Fields From One Site to Others with Meta Box Builder

  1. This is great material. It's really full of useful and interesting facts that anybody can grasp. I love reading articles so well-written. This content is superb and deserves a top rating.

Leave a Reply to Babe Cancel reply

Your email address will not be published. Required fields are marked *