I'm struggling to have an auto increment ID working in a dynamic field when a user submits a form. How should the custom table get updated for every submission entry? & How should we get the id from the custom table?
Create Table with auto increment:
function create_db() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . "id_count";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`name` mediumtext NOT NULL,
UNIQUE KEY id (id)
)$charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}
add_action("init", "create_db");
When form submit:
function your_wpcf7_posted_data( $posted_data ) {
global $wpdb;
$name = $posted_data['your-name'];
$table_name = $wpdb->prefix . "id_count";
$posted_data['cf7-counter'] = $wpdb->insert_id;
);