CMB2 Field Type: Flexible Content
A flexible content field for CMB2
by Reaktiv Studios · github.com/reaktivstudios/cmb2-flexible-content · website
★ 14stars
312composer installs
2forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/reaktivstudios/cmb2-flexible-content/archive/refs/heads/master.zipAlso on Packagist as reaktivstudios/cmb2-flexible-content:
composer require reaktivstudios/cmb2-flexible-contentFrom the readme
CMB2 Flexible Field
The CMB2 Flexible Field allows the creation of group layouts, which can then be selected and switched between by a user. Each layout group contains a set of existing CMB2 fields, defined in an array in the field setup. These layout groups are then toggleable, sortable and repeatable.
The data itself is saved to the field's ID in a serialized and iterable array with the layout group ID attached.
Adding a Flexible Field
Adding a flexible field is the same as adding any other CMB2 field. The only addition is the layouts option, which should contain an array of arrays, each with a separate group.
To begin, set up a standard CMB2 metabox:
Getting Data from a Flexible Field
Flexible fields are stored in a single meta key, and can be retrieved using the WordPress API. This will return an array of data, each with the layout key defined as layout and the group's data by field ID.