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
2684publicfunctionupdate($table,$data,$where,$format=null,$where_format=null){2685if(!is_array($data)||!is_array($where)){2686returnfalse;2687}26882689$data=$this->process_fields($table,$data,$format);2690if(false===$data){2691returnfalse;2692}2693$where=$this->process_fields($table,$where,$where_format);2694if(false===$where){2695returnfalse;2696}26972698$fields=array();2699$conditions=array();2700$values=array();2701foreach($dataas$field=>$value){2702if(is_null($value['value'])){2703$fields[]="`$field` = NULL";2704continue;2705}27062707$fields[]="`$field` = ".$value['format'];2708$values[]=$value['value'];2709}2710foreach($whereas$field=>$value){2711if(is_null($value['value'])){2712$conditions[]="`$field` IS NULL";2713continue;2714}27152716$conditions[]="`$field` = ".$value['format'];2717$values[]=$value['value'];2718}27192720$fields=implode(', ',$fields);2721$conditions=implode(' AND ',$conditions);27222723$sql="UPDATE `$table` SET $fields WHERE $conditions";27242725$this->check_current_query=false;2726return$this->query($this->prepare($sql,$values));2727}
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 6.9.7 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.