For the frontend form, I am trying to set the fields of the 'date' to today when they submit. This is my code:
add_action( 'rwmb_frontend_after_save_post', function( $object_post ) {
global $wpdb;
$postID = $object_post->post_id;
$tz = 'America/Los_Angeles';
$timestamp = time();
try {
$dt = new DateTime("now", new DateTimeZone($tz));
$dt->setTimestamp($timestamp);
$wpdb->query($wpdb->prepare("UPDATE wp_provider_units SET available='" . $dt->format('Y-m-d') . "' WHERE ID=". $postID . " AND (available IS NULL OR available = '' OR DATE(available) < CURRENT_DATE());"));
} catch (Exception $e) {
}
} );
All that does is set the date for wp_provider_units but apparently, the frontend form actually pulls values from postmeta table. I have no idea why that table is even being used with custom tables being active, but it is and even with that hook it does not update postmeta with the proper values.
I will note, this is a clone field, so I am trying to save the new date for all units with that post_id. Inside the postmeta table, it's serialized data that includes the entire array of the clone so I have no clue how to update just one field from that.
Basically, all I really need to do is overwrite the date field with today's date for each clone. I don't care if it's done via SQL or through the metabox method but any help is greatly appreciated. Thanks