I have created a custom Wordpress form and I am working on inserting the submissions into a custom table in my database. Passing single fields into the table is working great, but I also have an array I need to insert as well. I created a LONGTEXT
field, but when I try to insert the array into the field nothing is getting inserted.
Here is my $wpdb
insert code:
$name = $_POST['name'] ?? '';
$products = $_POST['products'] ?? '';
global $wpdb;
$tablename = $wpdb->prefix . 'orders';
$wpdb->insert($tablename,
array(
'name' => $name,
'products' => $products
),
array('%s', '%s')
);
The $products
variable is the array. How can I make it so that the array gets passed in the products
field of my custom table? Also, is LONGTEXT
the correct field type?