Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
$wherearray
A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw". Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
$formatstring[]|stringoptional
An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. Default null.Default: null
$where_formatstring[]|stringoptional
An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types. Default null.Default: null
2680publicfunctionupdate($table,$data,$where,$format=null,$where_format=null){2681if(!is_array($data)||!is_array($where)){2682returnfalse;2683}26842685$data=$this->process_fields($table,$data,$format);2686if(false===$data){2687returnfalse;2688}2689$where=$this->process_fields($table,$where,$where_format);2690if(false===$where){2691returnfalse;2692}26932694$fields=array();2695$conditions=array();2696$values=array();2697foreach($dataas$field=>$value){2698if(is_null($value['value'])){2699$fields[]="`$field` = NULL";2700continue;2701}27022703$fields[]="`$field` = ".$value['format'];2704$values[]=$value['value'];2705}2706foreach($whereas$field=>$value){2707if(is_null($value['value'])){2708$conditions[]="`$field` IS NULL";2709continue;2710}27112712$conditions[]="`$field` = ".$value['format'];2713$values[]=$value['value'];2714}27152716$fields=implode(', ',$fields);2717$conditions=implode(' AND ',$conditions);27182719$sql="UPDATE `$table` SET $fields WHERE $conditions";27202721$this->check_current_query=false;2722return$this->query($this->prepare($sql,$values));2723}
History
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wpdb.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.