Support Forum
Support › MB Frontend Submission › Front End Delete and WordPress database errorResolved
Hi
When I go to delete any post using the front end form and the delete button, it fires correctly and deletes the post but there is a WordPress database error in the PHP log. The issue is there with and without ajax enabled.
[mb_frontend_form id="dc-product" post_id=314 submit_button="Update" allow_delete="true" ajax="true"]
PHP error log (appears after the post has been deleted
[26-Feb-2022 23:15:32 UTC] WordPress database error Unknown column 'post_title' in 'field list' for query UPDATEwp_dc_products
SETID
= 314,type
= 'Ask',description
= 'aaaa',price
= '0.00',condition
= 'used',location
= 'Hucknall',end_date
= '2022-01-23 23:22:00',images
= 'a:1:{i:0;s:40:\"dc/products/314/ygm_yellowface_click.png\";}',start_date
= NULL,post_title
= 'Test Product New 3' WHEREID
= 314 made by do_action('wp_ajax_mbfs_delete'), WP_Hook->do_action, WP_Hook->apply_filters, MBFS\Shortcode->delete, MBFS\Form->delete, wp_delete_post, apply_filters('pre_delete_post'), WP_Hook->apply_filters, DripCreateProductComments->{closure}, wp_trash_post, wp_update_post, wp_insert_post, do_action('save_post_product'), WP_Hook->do_action, WP_Hook->apply_filters, RW_Meta_Box->save_post, do_action('rwmb_after_save_post'), WP_Hook->do_action, WP_Hook->apply_filters, MetaBox\CustomTable\Loader->update_object_data, MetaBox\CustomTable\Storage->update_row
I have tested a few posts and the same issue is there. I am using front end forms with a custom post type and custom tables.
Hi Nick,
I do not see that issue on my site. It looks like you are using custom fields to re-order default post fields but not create a corresponding column in the custom table.
https://docs.metabox.io/extensions/mb-frontend-submission/#reorder-post-fields
Can you please share the code that creates the custom fields in your case?
Hi Long,
I have found the issue, I added the following filter a few days ago; which I can confirm that once removed fixed the database error.
add_filter( 'pre_delete_post', function( $null, $post, $force_delete ) {
if( $force_delete == false ) {
return wp_trash_post( $post->ID );
}
return $null;
}, 10, 3 );
I added the above code as all my custom post types were being force deleted every time (when set to false) https://support.metabox.io/topic/deleting-custom-post_type-with-frontend-submission-form-permanently-deletes-post/
Any ideas why?
Thanks
Hi,
Still have not experienced that issue https://monosnap.com/file/1VPUg5tkOYnfpJi78FXgONGw4V1umk
Can you please remove the attribute post_id
in the shortcode, which is used to edit the existed post, then recheck this issue?
Hi
Ok so i have made 2 screen recordings.
I have removed the post_id from the shortcode and tested again with the 'pre_delete_post' filter active, you can see in the video that I receive the PHP database error in the logs.
https://drive.google.com/file/d/1a_p4exzFVSQlibYuhVhRZaYwKDlyjmwf/view?usp=sharing
I have also made another screen recording with the 'pre_delete_post' filter removed (commented out). I do not receive any PHP database errors.
https://drive.google.com/file/d/1RNFq7B-q62oa1HPBpLB3kCk2TAeskAjm/view?usp=sharing
Thanks
Hi Nick,
Can you please share the code that creates the custom fields and meta box dc-product
on your site?
Hi Long,
sure, here is my code. Do you need anything else?
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',
'id' => 'type',
'options' => array(
'Gift' => 'Gift',
'Ask' => 'Ask',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
[
'type' => 'text',
'name' => 'Title',
'id' => 'post_title',
'class' => 'dc-post-title',
'limit' => 50,
'required' => true,
],
[
'type' => 'textarea',
'name' => 'Description',
'id' => 'description',
'required' => true,
],
[
'type' => 'dc_flatpickr_calendar',
'name' => 'End Date (optional)',
'id' => 'end_date',
'attributes' => [ //my custom attributes
'altInput' => true,
'altFormat' => 'd-m-Y H:i',
'inline' => false,
'allowInput' => false,
'disableMobile' => false,
'minDate' => 'today',
'enableTime' => true,
'time_24hr' => false,
'enableSeconds' => false,
'defaultHour' => 0,
],
],
[
'type' => 'select',
'name' => 'Condition',
'id' => 'condition',
'options' => array(
'used' => 'Used',
'like new' => 'Like New',
'new' => 'New',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
[
'type' => 'select',
'name' => 'Location',
'id' => 'location',
'options' => array(
'Hucknall' => 'Hucknall',
),
'multiple' => false,
'placeholder' => "",
'select_all_none' => false,
'required' => true,
],
[
'type' => 'dc_image_to_base64',
'name' => 'Images',
'id' => 'images',
'attributes' => [
'max' => 6, //max of 10 files
'buttonlabel' => 'upload',
'maxWidth' => 300, //px
'maxHeight' => 300, //px
'description' => '(drag to reorder)',
//'maxFileSize' => 8000000', //default wp upload size
],
'saveToCustomFolder' => [
'enabled' => true, //enable folder save (default false)
'folder' => 'products', //foldername no slashes
'deleteOnUpdate' => true, //force deletetion
],
'required' => true,
],
],
];
return $meta_boxes;
}
Hi,
Thanks, I got the issue. As my previous reply here https://support.metabox.io/topic/front-end-delete-and-wordpress-database-error/#post-34179
The issue happens when you re-order the post fields (post_title) but you do not register a corresponding column in the custom table (post_title).
https://docs.metabox.io/extensions/mb-custom-table/#creating-custom-tables
https://docs.metabox.io/extensions/mb-frontend-submission/#reorder-post-fields
You can try to remove the field post_title and re-check this issue.
[
'type' => 'text',
'name' => 'Title',
'id' => 'post_title',
'class' => 'dc-post-title',
'limit' => 50,
'required' => true,
],
Hi
Ok i have removed the post_title field and can confirm that there is no error upon deletion.
So I have to create a duplicate database column to fix this issue? I just assumed that the post_title was automatically being populated in the post table.
also what i have also found another issue in relation to the following filter.
add_filter( 'pre_delete_post', function( $null, $post, $force_delete ) {
if( $force_delete == false ) {
return wp_trash_post( $post->ID );
}
return $null;
}, 10, 3 );
When you go to bulk delete the custom post type in wp admin area there is an error which displays. The error is 'error in deleting item'. But you can delete them one by one.
video here...
https://drive.google.com/file/d/1AXFUcDvjz-5cGE84USvEWHCCVEu77thI/view?usp=sharing
if I disable the filter above and then the bulk delete feature works.
Hi Nick,
You can add this setting 'save_field' => false
to the field post_title
to avoid showing the error. The custom field will not be saved data to the database, just use to display the value from default post field.
[
'type' => 'text',
'name' => 'Title',
'id' => 'post_title',
'class' => 'dc-post-title',
'limit' => 50,
'required' => true,
'save_field' => false // This
],
Regarding the error in bulk delete, I will inform the development team to support moving the CPT to the trash instead of using the filter. It should use to cover another case.
Hi Long,
Ok I have added the ('save_field' => false) and the error does not display in the logs anymore. Thanks
I have made a note to add this in to all forms and a linkback to this thread.
It would be great if the custom post type trash option would work in the core of Metabox plugin
also as a note I have added a check in the following filter for is_admin() which has fixed the bulk delete error message issue for now.
add_filter( 'pre_delete_post', function( $null, $post, $force_delete ) {
if( $force_delete == false ) {
if ( ! is_admin() ) {
return wp_trash_post( $post->ID );
}
}
return $null;
}, 10, 3 );