post meta – What am I doing wrong with update_post_meta?
I am using metabox frontend form for a clonable field that has a few options. However, using the hook ‘rwmb_frontend_before_save_post’, I tapped in to try and change the date of the field ‘available’ to today.
I excluded the code to get $currentDate for relevancy but it just responds with YYYY-MM-DD
$oldData= get_post_meta ($ID,'units', true);
foreach($oldData as $data):
$newDate = array(
'available' => $currentDate
);
update_post_meta( $ID, 'units', $newDate )
endforeach;
Other things I’ve tried:
Putting the code in ‘rwmb_frontend_after_save_post’ in the weird event it was just overwriting my data between ‘before’ and ‘after’.
I set the variable of the field itself to the current date but it doesn’t stick
foreach($_POST['units'] as $unit):
$unit['available'] = $dt->format('Y-m-d');
endforeach;
Another fun thing about Metabox is that I am using their custom table plugin so I have a wp_units table with all the fields that I call on throughout the site, but their frontend form updates both the custom table AND postmeta. And for some reason, their frontend form pulls from the data from postmeta. It’s the strangest thing. But that’s a weird metabox quirk.
Thanks!
Leave an answer