Support Forum
Support › MB Frontend Submission › Why wouldn't this update the data?
I posted another thread on the issue, but I tried a different method while waiting for a response and I am at a complete loss.
In the 'rwmb_frontend_before_process' hook, I do this:
foreach($_POST['provider_units'] as &$unit):
$unit['available'] = $dt->format('Y-m-d');
endforeach;
and throughout all the hooks, I pass this:
ca_log3(print_r($_POST['provider_units'], 1));
No matter where I call it, including 'rwmb_frontend_after_save_post', it shows this:
Array
(
[0] => Array
(
[available] => 2022-12-15
)
[1] => Array
(
[available] => 2022-12-15
)
)
So the available date is correctly being carried from when I changed it in pre-process all the way through the save process. Yet checking the postmeta table, it still shows as this (after unserializing)
Array
(
[0] => Array
(
[available] => 2022-09-01
)
[1] => Array
(
[available] => 2022-10-05
)
)
So why in the world would it not be updating the postmeta table in that hook? The _POST variable clearly shows 'available' being properly set to today, but it never updates the DB? I'm so confused.
Also, it IS being saved. I am using custom tables and actually pulling the data from those tables on my actual site and it shows the available date as 'today'. So the $_POST variable is saving in the custom table as it should, but it is NOT updating postmeta.
This is so frustrating. The postmeta table makes me want to ditch wordpress entirely!
Hello Amy,
Thanks for reaching out.
Can you please let me know the whole scenario and the code to register the fields, update the post meta ...
Did you try to just update the post meta with a single value like this?
update_post_meta( $post_id, 'field_id', 'testvalue' )
You can try to deactivate all plugins and leave only Meta Box, MB extensions and activate a standard theme of WordPress to check this issue again.
Hmm, there was a script written before I got here that converted cloned data to unserialized data into their custom fields. That could likely be causing some issues.
However, you did give me an idea I wish I thought of for debugging. Not sure why I didn't think of creating a test entry to play with that. I did that and saw all the ways I was updating PM wasn't inputting it correctly.
I did notice the correct PM serialized data was formatted just like above:
Array
(
[0] => Array
(
[available] => 2022-09-01
)
[1] => Array
(
[available] => 2022-10-05
)
)
So I just tried a non-loop basic
update_post_meta($id, 'field', $array)
and poof, updated properly! I was overthinking it.
And now to do some fun (sarcasm) stuff like adding extra features through javascript that the former dev hardcoded into the metabox files. I don't think there are any hooks for that, but I'll make it work.
Thanks for your help!