Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

vi:Tham Khảo Các Hàm/update option

Bản Nháp

Trang này được đánh dấu là bản nháp. Bạn có thể giúp đỡ WordPressVN bằng cách hoàn thiện trang này.


Use the function update_option to update a named option/value pair to the options database table. The option_name value is escaped with $wpdb->escape before the INSERT statement.

Proper use of this function suggests using get_option to retrieve the option and if tested for true, then use update_option. If get_option returns false, then add_option should be used instead.

Note that update_option cannot be used to change whether an option is to be loaded (or not loaded) by wp_load_alloptions. In that case, a delete_option should be followed by use of the update_option function.


<?php update_option('option_name''newvalue'); ?>


Update the option name myhack_extraction_length with the value 255. If the option does not exist then use add_option and set autoload to no.

$newvalue '255' ;
  if ( 
get_option($option_name) ) {
  } else {
$deprecated=' ';


(string) (required) Name of the option to update. A list of valid default options to update can be found at the Option Reference.
Default: None
(string) (required) The NEW value for this option name. This value can be a string, an array, an object or a serialized value.
Default: None
This article is marked as in need of editing. You can help Codex by editing it.