When a new popup block is added, the field "cta-popup-unique-id" has the initial value of "popup-". I'm trying to check if a unique id has been generated for the popup already and if not, then create it.
My code below currently does generate new unique ID and it adds it correctly to the variable $blockRevealId as I'm using it later in the template. My issue here is that the update_field() is not saving the newly generated id into this field and a new unique id is generated on each page load.
So I would need the unique id to be only generated first time the page is loaded and then save that id into the ACF field.
// Check if ID has been generated and if not, generate it
$blockRevealId = get_field('cta-popup-unique-id');
if ($blockRevealId == 'popup-') {
// If ID is empty, generate new one which is 10 chars long
$randString = createRandString(10);
// Add random string as ID to popup
$blockRevealId .= $randString;
// Update the field
update_field('cta-popup-unique-id', $blockRevealId);
}