Issue Summary
When creating custom $wpdb table and custom entries (with wp functions) local creates duplicated entries while it should create only one. For example $wpdb->insert(…);
It only happens on local. Tested on XAMPP and this behaviour does’t happen (both local/xampp ssl https).
Tested with empty theme (only empty style.css, empty functions.php, empty index.php) No plugins installed, brand new site and database.
Troubleshooting Questions
-
Does this happen for all sites in Local, or just one in particular? All.
-
Are you able to create a new, plain WordPress site in Local and access it in a Browser? Yes.
Replication
Create these 2 functions in functions.php. (first to create a table, second to create an entry).
It should creat 1 entry to that table on each page reload. But instead it creates 2 entries in the table.
function create_table($table_name){
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . $table_name;
$sql = "CREATE TABLE $table_name (
id int(10) NOT NULL AUTO_INCREMENT,
user_name varchar(100) DEFAULT '' NOT NULL,
password varchar(100) DEFAULT '' NOT NULL,
email varchar(100) DEFAULT '' NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
create_table('test');
function insert_to_table($table_name){
global $wpdb;
$table_name = $wpdb->prefix . $table_name;
$wpdb->insert(
$table_name,
array(
'user_name' => 'user',
'password' => 'pass',
'email' => 'myemail',
),
array(
'%s',
'%s',
'%s',
)
);
}
insert_to_table('test');
System Details
-
Which version of Local is being used? local 5.10.1
-
What Operating System (OS) and OS version is being used? Mac OS 11.2.2 & 10.15.7
- For example: macOS Catalina or Windows 10 Professional
-
Attach the Local Log. See this Community Forum post for instructions on how to do so: