I guess that you have heard or even used the Flexible Content Field from Advanced Custom Fields (ACF) plugin. Haven’t you? If you are looking for ways to create it but don’t want to use ACF, follow this post. I will guide you to create one kind of ACF Flexible Content Field, but using Meta Box plugin to do.

Because of using a tool which is not ACF, there are some definitions which are different from the ones called by ACF. We will find out each one below.

Let’s make them clear.

What is Meta Box?

Meta Box is a simple yet powerful plugin that helps developers build custom meta boxes and custom fields in WordPress fast and easily.

We have published a very detailed post about Meta Box, how to use it, and what are its advantages. Please spend several minutes finding out here.

In this post, we also present 2 its extensions, which are the main tools to use in this tutorial, are: Meta Box Group and Meta Box Conditional Logic.

Meta Box Group

Meta Box Group is an extension of Meta Box plugin. It allows you to group fields together, organize and rearrange them to have a visually-stunning hierarchy. It also helps you to clone fields in an easy way, or make groups be collapsible.

This is a premium extension from Meta Box, so you need to pay for it. You may buy this plugin individually or buy a Meta Box’s bundle of extensions which includes many helpful extensions and saves you money.

Meta Box Conditional Logic

Meta Box Conditional Logic, like Meta Box Group, is an extension of Meta Box. As said by its name, it allows you to assign a condition for any field to set when that field displays. This condition will base on the value of another field.

This is a premium extension of Meta Box, so you need to pay for it as well.

What is Flexible Content Field?

Flexible Content Field (ACF)

Flexible Content Field is a type of field supported by ACF. It allows you to create a layout including different sections and each one includes different sub-fields. Among the sections, you can clone anyone you want.

View this video to know more about what Flexible Content Field can do:

Group Field (Meta Box)

Meta Box plugin actually has no field which is equivalent to ACF Flexible Content Field. So that, to create that kind of field, I will use a field type named Group of Meta Box.

Meta Box Group Album example

In order to create this field, Group Field, we will use Meta Box Group.

This Group Field will help you group the fields together, create sub-group, and clone its sub-field / sub-group as well. This all features is available in Flexible Content Field of ACF.

However, Group Field’s nature does not include assigning a field can be displayed based on another field’s value (but Flexible Content Field of ACF has). Fortunately, Meta Box has another interesting extension named Meta Box Conditional Logic that can do it.

Whenever you combine Meta Box Group and Meta Box Conditional Logic, the Group Field will have all the features which Flexible Content Field of ACF has, even more. We will explore their abilities when combining them together in later posts.

Now, come back to creating fields.

How to create Flexible Content Field without ACF, but using Meta Box

Before getting started

We need to install and activate all the below plugins:

Remember to activate all of them.

In additional, if you want to create and configure the fields with a visual and intuitive interface and don’t want to touch any code, you should use Meta Box Builder. I did it in this post.

Learn more about how to install and activate plugins here.

Get started to create Flexible Content Field

I will summarize the process for you to get the overall view.

Firstly, I will create a parent group, then a field in the select type and sub-groups inside the parent group. Secondly and also finally, I will assign a condition to the sub-groups to set when each one displays.

It is pretty easy, isn’t it? Let’s do it.

Step 1: Create a parent group

In the admin dashboard, find the tabs Meta Box > Custom Fields. Then, look at the Specials tab (see the below image to know where it is) and press “Group“. A field in group type will appear in the right area.

Create group by Meta Box to make flexible content field

I set it to name “Sections” and tick the boxes “Cloneable” (which allows you to clone this group) and “Collapsible” (which allows you to collapse or expand this group).

configure the group by Meta Box to create flexible content field

Step 2: Create a Select Field insides the above parent group

Similar to the way of creating the parent group, just look for Basic Fields tab and then choose “Select”.

Create select field by Meta Box to create flexible content field

Pay attention that the created Select Field has not been inside the parent group yet. Drag and drop it to the group, then it became a sub-field of the parent group.

drag and drop field anywhere with Meta Box

There is no need to configure this field now, just skip it and move on. We will configure it in the final step.

Step 3: Create sub-groups inside the parent group

I’m going to create 3 sub-groups, each one will be proportional to one option in the Select Field.

  • 1st sub-group – Services: we create an additional and cloneable sub-group inside this one. This section represents the services as said by its name, so it would be repeatable.
  • 2nd sub-group – Testimonials: we also create a sub-group insides this one.
  • 3rd sub-group – Facts: this sub-group will include a text field, a textarea field, and a sub-group as well.

In order to create these fields and sub-groups, just choose field types in the left bar, then drag and drop them to rearrange. Let’s see my achievement:

fields structure created by Meta Box to create flexible content field

Step 4: Assign conditional logic to the fields / groups

Now, we will set up the conditions to sub-groups to be displayed only when the Select Field has proportion value.

This is the final step and the most difficult one to express. Please take a look at the image for more explanation.

Back to the Select Field. In the configuration area of this field, add options which are proportional to the name of sub-groups. In this tutorial, I added Services, Testimonials, and Facts as the name of my sub-groups.

Add options for Select field of Meta Box

Then, go to the group named “Services”, choose the Advanced tab, then + Condition and start to add a condition.

I will set up it as below:

  • Choose Visible when All of these conditions match. Choosing “All” or “Any” have no meaning in this case because we are going to enclose only 1 condition.
  • Enter the condition values. In there:
    • select: the ID of the Select Field;
    • Value: is one of option we added in the Select Field. It is the value when you want the sub-group (which you are setting for) to be displayed.

Set condition for a group of custom fields

Do the same thing for the remaining sub-groups, but remember to change the “value” in the last step.

Set condition for a group of custom fields
Set condition for the Testimonials sub-group
Set condition for a group of custom fields
Set condition for the Facts sub-group

Now, we have done. Just press “Save” now.

Result

After saving the custom fields and groups, now edit a page. If nothing goes wrong, you’ll see the result like this:

Create ACF Flexible Content Field with Meta Box Group

As you see, it’s very similar to ACF Flexible Content Field. You can add a section for your content, select what type of the section and fill in all the fields that section might have.

Create Flexible Content Field with Code

If you don’t use Meta Box Builder to create fields and groups visually, you can always do that with code. Below is the code for all the above set up. Just copy and paste it into your functions.php file of your theme and you’re done!

Final words

Flexible Content Field is a very interesting feature from the PRO version of the Advanced Custom Fields plugin. It allows you to build groups with different sub-fields based on their type. In this tutorial, I’ve guided you to achieve the same thing using Meta Box’s extensions. You might want to explore more features of Meta Box Group, Meta Box Conditional Logic to see what they are capable for. And if you have any comment, please let us know below.

Leave a Reply