If you want a group that’s not repeatable, than it’s likely you want a separate metabox. Can you explain why you would need a non-repeatable group? If it’s to differentiate a section, you could use the title
field type to separate them.
Thread Starter
John_G
(@john_g)
It does not matter if it is separate metabox or not. The design of the plugin does not allow to save group(if not using type=>group) as a single meta entry. Everything results in a mess of metas. One have to deal with multiple get_post_meta instead of retrieving all the corresponding data in one go.
You should not overthink anything. Group filed is a group firstly. Repeatable is different story.
you can get all of the post meta on a post with 1 get_post_meta()
call, for what it’s worth, but it fetches EVERYTHING and you’d need to filter out what you don’t need. Just provide the ID of the post and nothing else.
Thread Starter
John_G
(@john_g)
Consider such scenario: you need to combine JSON for client side. With single get_post_meta
you will have to filter metas by hand and repeat keys (keys for filtering = cmb2 metabox field ids
):
$metas = get_post_meta($id);
$keys = array_keys($keys_i_need);
$filtered = array();
foreach ($metas as $key => $value)
{
if (in_array($key, $keys))
{
$filtered[$key] = $value;
}
}
Ever find a workable solution for this John_G?
Good to know you found something to work. Have a good day.