WordPress:Function Reference/update option

来自站长百科
Fludlen讨论 | 贡献2008年7月22日 (二) 13:28的版本
跳转至: 导航、​ 搜索

Description

描述

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.

使用函数update_option将指定的选项/选项值更新到选项数据库表格。在插入声明之前,option_name value is escaped with %%%$wpdb->escape%%%。

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.


合理地使用选项,建议使用get_option得到选项,如果测试为真的,然后使用update_option。如果get_option返回错误的,那么应该使用add_option

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.

注意update_option可以用来更改选项是否通过wp_load_alloptions载入(或者没有载入)。在这种情况下,delete_option应该在接着使用update_option函数。

Usage

用法

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

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

Example

例子

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.

更新参数值255的选项名myhack_extraction_length。如果这个选项不存在,使用add_option并且将自动载入设置为无。

%%%<?php $option_name = 'myhack_extraction_length' ; $newvalue = '255' ;

 if ( get_option($option_name) ) {
   update_option($option_name, $newvalue);
 } else {
   $deprecated=' ';
   $autoload='no';
   add_option($option_name, $newvalue, $deprecated, $autoload);
 }

?>%%%


%%%<?php $option_name = 'myhack_extraction_length' ; $newvalue = '255' ;

 if ( get_option($option_name) ) {
   update_option($option_name, $newvalue);
 } else {
   $deprecated=' ';
   $autoload='no';
   add_option($option_name, $newvalue, $deprecated, $autoload);
 }

?>%%%

Parameters

参数