Try something like this
function insert_data_into_table () {
global $wpdb;
$table_name = $wpdb->prefix . "your_table_name";
//Check if table exists
if($wpdb->get_var("show tables like '$table_name'") != $table_name) :
//if not, create the table
$sql = "CREATE TABLE " . $table_name . " (
(...)
) ENGINE=InnoDB;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
else:
foreach($emails as $mail):
$insert = "INSERT INTO " . $table_name . "
(post_id, post_id, email, post_id)
VALUES ($post_id, $user_id, email['content'], 1);"
$results = $wpdb->query( $insert );
endforeach;
endif;
}
I’m assuming that $email
is an array containing some data? If you want to save the entire array, then you should serialize()
the array.