- I created a php class on a separate file
- I included the file in functions.php
- I initialized the class
The class among many other things has one functions that does this:
$data = array( 'time' => date('Y-m-d H:i:s'), 'offset' => 0, ); $format = array( '%s', '%d' ); $wpdb->insert('my_custom_table',$data,$format);
One page load the class runs, and for some reason I get 2 entries in the database instead of one. The data is correct, but I don't know why I have 2 entries if I only inserted once.
In my class $wpdb->insert only runs once. I can test that buy echoing anything right next to it.
So I removed $wpdb->insert outside the class and added directly to functions.php. I noticed that the $wpdb->insert was running 2 or more times.
What's causing it to run multiple times?
No, I don't have a loop. Yes, I know I should not run it in functions.php, but it' for testing only.
I have found similar questions, but no good answer.