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
2678publicfunctionupdate($table,$data,$where,$format=null,$where_format=null){2679if(!is_array($data)||!is_array($where)){2680returnfalse;2681}26822683$data=$this->process_fields($table,$data,$format);2684if(false===$data){2685returnfalse;2686}2687$where=$this->process_fields($table,$where,$where_format);2688if(false===$where){2689returnfalse;2690}26912692$fields=array();2693$conditions=array();2694$values=array();2695foreach($dataas$field=>$value){2696if(is_null($value['value'])){2697$fields[]="`$field` = NULL";2698continue;2699}27002701$fields[]="`$field` = ".$value['format'];2702$values[]=$value['value'];2703}2704foreach($whereas$field=>$value){2705if(is_null($value['value'])){2706$conditions[]="`$field` IS NULL";2707continue;2708}27092710$conditions[]="`$field` = ".$value['format'];2711$values[]=$value['value'];2712}27132714$fields=implode(', ',$fields);2715$conditions=implode(' AND ',$conditions);27162717$sql="UPDATE `$table` SET $fields WHERE $conditions";27182719$this->check_current_query=false;2720return$this->query($this->prepare($sql,$values));2721}
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.8.8 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.