I have create a form and i want to store the form data in wp_options table so for that i have created this query

$insertquery = $wpdb->query("INSERT INTO `wp_options`(`option_name`,`option_value`) VALUES ('smsfactory123','asdasdf')");

Now when i am importing the static data then it doesn't create any problem when i pass the variable which is containing array it shows me error.

$apidetail = array(
    'userid' => $uid,
    'userpassword' => $upwd,
    'senderid' => $sid,
    'ono' => $ono,
    'message' => $message,

This is how i am getting value of array in variable


You could also use json_encode() function instead of serialize.

$var = json_encode($array);
update_option('option_name', $var); 
  • So it will insert data into wp_options table? – Jayant Rawat Feb 19 '16 at 10:30
  • 2
    You could also consult the small green martians, but for some reason you don't attempt to do that, if serializing is a waste, json is just idiotic. – Mark Kaplun Feb 19 '16 at 10:37
  • Well Well Well it works for me so now i come to know that how to insert value in wp_options table thanks a lot @maximus L – Jayant Rawat Feb 19 '16 at 10:39

You can save array with update_option function like below code.

update_option('option_name', $arr_store_me);  
  • why do you serialize the value? – Mark Kaplun Feb 19 '16 at 10:01
  • It is not necessary but i suppose they need to save array in one meta so it is best. – Devendra Sharma Feb 19 '16 at 10:07
  • beyond the slight waste of CPU, It gives the impression it is needed.... – Mark Kaplun Feb 19 '16 at 10:35
  • Hey i am creating plugin for first time so i want to insert data to wp_options so the way you are telling is it save the value to option_value? – Jayant Rawat Feb 19 '16 at 10:36
  • Yes, You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is inserted into the database. – Devendra Sharma Feb 19 '16 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.