您在问题中显示的选项是序列化数组。使用检索选项get_option()
返回数组,但未序列化。这是由maybe_unserialize()
, 哪一个get_option
使用。只需添加一个新的\'key\' => \'value\'
与检索到的数组配对,然后使用更新选项update_option()
, 等等,你为你的选择增加了额外的价值。
如评论中所述,我不明白为什么它不起作用,如前所述,下面是一些肯定有效的示例代码:
// this is just for proof of concept
// add new data, we don\'t want to temper with the original
// it is an array to resemble your case
$new_new_arr = array(
\'key01\' => \'value01\',
\'key02\' => \'value02\'
);
// debug the data
print_r( $new_new_arr );
// now we actually add it tp wp_options
add_option( \'new_new_opt\', $new_new_arr );
// lets get back what we added
$get_new_new_arr = get_option( \'new_new_opt\' );
// debug the data
print_r( $get_new_new_arr );
// lets create the second array with the additional key => value pair
$add_new_new_opt = array( \'key03\' => \'value03\' );
// debug the data
print_r( $add_new_new_opt );
// lets combine, merge the arrays
$upd_new_new_arr = array_merge( $get_new_new_arr, $add_new_new_opt );
// debug the data
print_r( $upd_new_new_arr );
// now update our option
update_option( \'new_new_opt\', $upd_new_new_arr );
// get back the updated option
$get_upd_new_new_arr = get_option( \'new_new_opt\' );
// debug the data
print_r( $get_upd_new_new_arr );
// lets cleanup and delete the option
delete_option( \'new_new_opt\' );