Support Forum
Support › MB Custom Table › rwmb_set_meta for custom tableResolved
Hi,
I am hooking into a function of the wp all import-plugin to readout data from a serialized regular custom field and move it over to a metabox-field, which is in a custom table. this is my code to loop through the various fields:
$data = get_post_meta( $postid, 'all_data', true);
$fields = [
'address',
'city',
'zip',
'state',
'email',
'url',
'phone'
];
// Loop through data
foreach( $fields as $field ) {
if( array_key_exists( $field, $data ) ) {
rwmb_set_meta(
$postid,
$field,
sanitize_text_field( $data[$field] )
);
}
}
If I push data to error_log I can see all the necessary data. However, rwmb_set_meta does not save anything. My custom table is empty 🙁
What do I do wrong?
Hi,
The helper function rwmb_set_meta() has not worked with the field which saved value in the custom table yet, only the default table wp_postmeta
of WordPress.
I'm going to inform the development team to cover this case in future updates. Thank you.
Hi,
Thanks for the quick answer. So... how do I save my fields in the custom table then? Would this really be a direct call to $wpdb?
Thanks,
Michael
Hi,
Yes, for now, please use the class $wpdb
to update the field value in the custom table.
https://developer.wordpress.org/reference/classes/wpdb/
Hi,
Is there any update on this feature?
We cannot rely on wpdb->insert() forever. Would appreciate if rwmb_set_meta() works with custom table even if the values are not saved yet.
Many thanks
Lee
Hi Lee,
This issue has been fixed. Please read more on the documentation (scroll down to the bottom) https://docs.metabox.io/functions/rwmb-set-meta/
or use the MB Custom Table API add
or update
to set or update the field value. Read more on the documentation https://docs.metabox.io/extensions/mb-custom-table/#add