Support Forum
Support › MB Custom Table › Custom Table Values - Not Saving To The Custom TablesResolved
Hi,
I have been using custom tables with front end forms for while now and only since the Mb Custom Table 2.1.2 update I have issues with non of the custom table fields/values are saving into the custom database table. The only values which are saved are the default wp meta values e.g. post_title. This happens for new and updating posts. Also this happens for any front end shortcode pointing to a custom table. So not an isolated issue.
I have changed nothing in my project setup for months and when i revert back to MB Custom Table 2.1.1 the problem goes away. So i know the issue is with the update? any ideas why?
Also I have checked my PHP logs and I cannot see any errors and the forms successfully pass validation.
Here are some of the forms which I'm using for reference.
$meta_boxes[] = [
'title' => 'Products',
'post_types' => 'product', //target product cpt
'storage_type' => 'custom_table', //store in custom table not default wp post meta table
'table' => $wpdb->prefix . 'dc_products', // custom mysql table name
'id' => 'dc-product', //metabox
'context' => 'normal',
'fields' => [
[
'type' => 'select',
'name' => 'Type', //label for form
'id' => 'type', //mysql table col
'options' => array(
'gift' => 'Gift',
'ask' => 'Ask',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
...
$meta_boxes[] = [
'title' => 'Edit Profile', //hidden as this form is used for register and updating profile
'type' => 'user', //target wp users
'storage_type' => 'custom_table', // //store in custom table not default meta table
'table' => $wpdb->prefix . 'dc_users', // custom table name
'id' => 'dc-user', //metabox id
'context' => 'normal',
'fields' => [
[
'type' => 'text',
'name' => 'First Name', //label for form
'id' => 'first_name', //mysql name (default user field in user table)
'required' => true,
],
[
'type' => 'text',
'name' => 'Last Name', //label for form
'id' => 'last_name', //mysql name (default user field in user table)
'required' => true,
],
[
'type' => 'email',
'name' => 'Email',
'id' => 'user_email', //target defaut wp metaname
'required' => true,
],
[
'type' => 'text',
'name' => 'Address', //label for form
'id' => 'address', //mysql name
//'placeholder' => 'e.g. 10 Bond Street',
'required' => true,
]...
Hi,
I'm not able to reproduce that issue on my site. Can you please create a new field group (meta box) and recheck this issue?
Hi, ok when you say a new field group, are you on about adding in a 'metabox group'? https://docs.metabox.io/extensions/meta-box-group/
also when i go to edit a post using the same shortcode and populating the if from the url e.g. http://192.168.0.14/stagingsite/edit-product/?rwmb_frontend_field_post_id=387
The values are loaded correctly (so its reading from the custom database table ok), just not updating it when the form is submitted.
Hi Nick,
I remember that you've created a ticket (with the Helpdesk system) and asked about this issue. Can you please share the site credentials via that ticket again?
Hi
I had some time this morning and somehow I figured out what the issue seems to be. When i have more than one metabox targeting the same post type it fails to update or create new entries. This is only and issue in the latest version of MB Custom Table Addon (v2.1.2)
'post_types' => 'product'
e.g.
add_filter( 'rwmb_meta_boxes', 'dc_product_register_meta_boxes' );
function dc_product_register_meta_boxes( $meta_boxes ) {
global $wpdb;
$meta_boxes[] = [
'title' => 'Products',
'post_types' => 'product', // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'storage_type' => 'custom_table',
'table' => $wpdb->prefix . 'dc_products',
'id' => 'dc-product',
'context' => 'normal',
'fields' => [
[
'type' => 'select',
'name' => 'Type', //label for form
'id' => 'type', //mysql table col
'options' => array(
'gift' => 'Gift',
'ask' => 'Ask',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
[
'type' => 'text',
'name' => 'Title', //label for form
'id' => 'post_title', //stored in wp 'post title'
'class' => 'dc-post-title',
//'placeholder' => 'e.g. Wardrobe',
'limit' => 50, //default character length
//'limit type' => 'word', //change to word count instead of character
'required' => true,
//'save_field' => false
],
[
'type' => 'textarea',
'name' => 'Description', //label for form
'id' => 'description', //mysql table col
'required' => true,
],
// [
// 'type' => 'dc_flatpickr_calendar',
// 'name' => 'Start Date', //label for form
// 'id' => 'start_date', //mysql table col
// 'attributes' => [ //my custom attributes
// 'altInput' => true,
// 'altFormat' => 'd-m-Y',
// 'inline' => false,
// 'allowInput' => false,
// 'disableMobile' => false,
// ],
// 'required' => true,
// ],
[
'type' => 'dc_flatpickr_calendar',
'name' => 'End Date (optional)', //label for form
'id' => 'end_date', //mysql table col
'attributes' => [ //my custom attributes
'altInput' => true,
'altFormat' => 'd-m-Y H:i',
'inline' => false,
'allowInput' => false,
'disableMobile' => false,
'minDate' => 'today',
'enableTime' => false,
'time_24hr' => false,
'enableSeconds' => false,
'defaultHour' => 0,
],
//'required' => true,
],
// [
// 'type' => 'number',
// 'name' => 'Price', //label for form
// 'id' => 'price', //mysql table col
// 'step' => '.01', //two decimal places e.g. 0.00
// 'placeholder' => '0.00',
// 'required' => true,
// ],
[
'type' => 'select',
'name' => 'Condition', //label for form
'id' => 'condition', //mysql table col
'options' => array(
'used' => 'Used',
'like new' => 'Like New',
'new' => 'New',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
[
'type' => 'select',
'name' => 'Location', //label for form
'id' => 'location', //mysql table col
'options' => array(
'Hucknall' => 'Hucknall',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
],
];
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'dc_product_deletion_register_meta_boxes' );
function dc_product_deletion_register_meta_boxes( $meta_boxes ) {
global $wpdb;
$meta_boxes[] = [
'title' => 'Test',
'post_types' => 'product', // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'storage_type' => 'custom_table',
'table' => $wpdb->prefix . 'dc_test',
'id' => 'dc-product-test',
'context' => 'normal',
'fields' => [
[
'type' => 'textarea',
'name' => 'Test', //label for form
'id' => 'test', //mysql table col
'required' => true,
],
],
];
return $meta_boxes;
}
also i noticed the same issue happens when targeting
'type' => 'user'
e.g.
add_filter( 'rwmb_meta_boxes', 'dc_users_register_meta_boxes' );
function dc_users_register_meta_boxes( $meta_boxes ) {
global $wpdb;
$meta_boxes[] = [
'title' => '',
'type' => 'user', //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'storage_type' => 'custom_table',
'table' => $wpdb->prefix . 'dc_users', // custom table name
'id' => 'dc-user-register', //metabox id
'context' => 'normal',
'fields' => [
[
'type' => 'text',
'name' => 'First Name', //label for form
'id' => 'first_name', //mysql name (custom table)
'required' => true,
],
[
'type' => 'text',
'name' => 'Last Name', //label for form
'id' => 'last_name', //mysql name (custom table)
'required' => true,
],
[
'name' => 'Email',
'id' => 'user_email', //REQUIRED (default WP field)
'type' => 'email',
'required' => true,
],
[
'name' => 'Password',
'id' => 'user_pass', //REQUIRED (default WP field)
'type' => 'dc_password_strength_checker',
'required' => true,
'attributes' => [
'minCharacters' => 8, //min password length
'lowerUpperCase' => true, //contain lower & uppercase
'numbers' => true, //contain numbers
'specialCharacters' => false, //contain special characters
],
],
// [
// 'name' => 'Password',
// 'id' => 'user_pass', //REQUIRED (default WP field)
// 'type' => 'password',
// 'required' => true,
// 'desc' => '<span id="password-strength" class="rwmb-password-strength"></span>',
// 'attributes' => [
// 'autocomplete' => 'new-password' //browser suggest a strong password
// ],
// ],
// [
// 'name' => 'Confirm Password',
// 'id' => 'user_pass2', //REQUIRED (default WP field)
// 'type' => 'password',
// 'required' => true,
// 'attributes' => [
// 'autocomplete' => 'new-password' //browser suggest a strong password
// ],
// ],
],
];
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'dc_users_profile_meta_boxes' );
function dc_users_profile_meta_boxes( $meta_boxes ) {
global $wpdb;
$meta_boxes[] = [
'title' => 'Edit Profile',
'type' => 'user', //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'storage_type' => 'custom_table',
'table' => $wpdb->prefix . 'dc_users',
'id' => 'dc-user',
'context' => 'normal',
'fields' => [
[
'type' => 'text',
'name' => 'First Name', //label for form
'id' => 'first_name', //mysql name (default user field in user table)
'required' => true,
],
[
'type' => 'text',
'name' => 'Last Name', //label for form
'id' => 'last_name', //mysql name (default user field in user table)
'required' => true,
],
[
'type' => 'email',
'name' => 'Email',
'id' => 'user_email', //target defaut wp metaname
'required' => true,
],
[
'type' => 'text',
'name' => 'Address', //label for form
'id' => 'address', //mysql name
//'placeholder' => 'e.g. 10 Bond Street',
'required' => true,
],
[
'type' => 'text',
'name' => 'City', //label for form
'id' => 'city', //mysql name
'required' => true,
],
[
'type' => 'text',
'name' => 'Town', //label for form
'id' => 'town', //mysql name
'required' => true,
],
[
'type' => 'text',
'name' => 'Postcode', //label for form
'id' => 'postcode', //mysql name
'required' => true,
],
[
'name' => 'Country', //label for form
'id' => 'country', //mysql name
'type' => 'hidden', //set to hidden as not used
'std' => 'United Kingdom', //set default value to UK (as no plans to expand beyond the uk)
],
[
'type' => 'dc_image_to_base64', //type of field (metabox ones or custom)
'name' => 'Profile Image', //label for form
'id' => 'image', //mysql table name
'attributes' => [
'max' => 1, //max of 10 files
'buttonlabel' => 'upload',
'maxWidth' => 300, //px
'maxHeight' => 300, //px
//'maxFileSize' => 8000000', //default wp upload size
],
'saveToCustomFolder' => [
'enabled' => true, //enable folder save (default false)
'folder' => 'profile', //foldername no slashes
'deleteOnUpdate' => true, //force deletetion of images uploaded before
],
'required' => true,
],
],
];
return $meta_boxes;
}
Hi,
Thanks for your additional information.
I've escalated this issue to the development team to investigate the issue and get back to you later.
I believe that I am also affected by this bug. Since updating Meta Box AIO, my custom fields saving to a custom table no longer work.
Please let us know when a fix is available. Also, can you also give us a way to rollback extensions/AIO? I think it would save people a lot of time when trying to diagnose stuff like this. See https://support.metabox.io/topic/how-to-access-older-versions-of-extensions/.
I have now rolled back to the last version of AIO that I manually downloaded, which appears to work for now.
i am also affected by this bug, i hope this bug is fixed soon
Thanks for the update, the latest version now works