ka2 on "[Plugin: Custom DataBase Tables] Update Data Feature and Enquiry"

ساخت وبلاگ

Thank you for your inquiry.

Yes, you can add the custom fields and customize the process at the time of updating data. I will introduce the sample code as an example below.

Sample table:

CREATE TABLE wp_products ( ProductID bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Product ID', ProductName varchar(200) NOT NULL, Quantity int(11) unsigned NOT NULL DEFAULT '0', created datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created Datetime', updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated Datetime', PRIMARY KEY (ProductID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

Sample Post:

[cdbt-edit table="wp_products"]

Filter hooks: ("functios.php" in theme)

function add_custom_field_wp_products( $elements_options, $shortcode_name, $table ){ if ( is_null( get_post() ) && 'cdbt-entry' === $shortcode_name && 'wp_products' === $table ) { $elements_options[] = [ 'elementName' => 'ChangeQuantity', 'elementLabel' => 'Addition/Subtraction', 'elementType' => 'number', 'isRequired' => false, 'defaultValue' => 0, 'placeholder' => 'Enter changing quantity', 'addClass' => '', 'selectableList' => '', 'horizontalList' => false, 'elementSize' => 2, 'helperText' => '', 'elementExtras' => [] ]; $element_order = [0,1,3,2]; array_multisort( $element_order, $elements_options ); } retu $elements_options;
}
add_filter( 'cdbt_shortcode_custom_forms', 'add_custom_field_wp_products', 10, 3 );
function custom_update_wp_products( $data, $table_name, $data_field_format ){ if ( ! is_admin() && 'wp_products' === $table_name && isset( $_POST['custom-database-tables']['ChangeQuantity'] ) ) { if ( intval( $_POST['custom-database-tables']['ChangeQuantity'] ) !== 0 ) { $data['Quantity'] += intval( $_POST['custom-database-tables']['ChangeQuantity'] ); } } retu $data;
}
add_filter( 'cdbt_before_update_data', 'custom_update_wp_products', 10, 3 );

By the above code, you can have the additional field for addition or subtraction and custom update process. I have uploaded the demo page of this sample, please try to see.

Please refer below full description for each filters (sorry in Japanese only).

https://ka2.org/cdbt/v2/filter-reference/cdbt_shortcode_custom_forms/
https://ka2.org/cdbt/v2/filter-reference/cdbt_before_update_data/

Thank you,

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 79 تاريخ : چهارشنبه 8 ارديبهشت 1395 ساعت: 9:54