CMB2-Snippet-Library
CMB2-Snippet-Library copied to clipboard
address field type
I've noticed with the address field type, if the values are empty, the array keys are still added IF the field type is set to repeatable in the metabox.
This becomes problematical when checking to see if an array is empty or not. If I'm looping through a repeatable cmb2 metabox that's using an address field for each entry for instance.
Shouldn't the array keys be unset if there's no value in them?
if you do something like $value = array_filter( $value ), you can check if empty( $value ) as it will filter out array keys that have no value.
Sure, tried that, unfortunately the order of the structure of my code is such that the custom snippet I've created (based on this address one), is just one of a number of fields in a group repeatable structure. That repeatable structure is also surrounded by structural html specific to it, that's not within a loop.
The upshot is, I'm checking for empty on the array that holds the custom fields array - so array_filter doesn't work as expected.
Everything works as expected if the custom field isn't set as repeatable - so I've got around it by just replicating as many fields as I may possibly require.