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
2674publicfunctionupdate($table,$data,$where,$format=null,$where_format=null){2675if(!is_array($data)||!is_array($where)){2676returnfalse;2677}26782679$data=$this->process_fields($table,$data,$format);2680if(false===$data){2681returnfalse;2682}2683$where=$this->process_fields($table,$where,$where_format);2684if(false===$where){2685returnfalse;2686}26872688$fields=array();2689$conditions=array();2690$values=array();2691foreach($dataas$field=>$value){2692if(is_null($value['value'])){2693$fields[]="`$field` = NULL";2694continue;2695}26962697$fields[]="`$field` = ".$value['format'];2698$values[]=$value['value'];2699}2700foreach($whereas$field=>$value){2701if(is_null($value['value'])){2702$conditions[]="`$field` IS NULL";2703continue;2704}27052706$conditions[]="`$field` = ".$value['format'];2707$values[]=$value['value'];2708}27092710$fields=implode(', ',$fields);2711$conditions=implode(' AND ',$conditions);27122713$sql="UPDATE `$table` SET $fields WHERE $conditions";27142715$this->check_current_query=false;2716return$this->query($this->prepare($sql,$values));2717}
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.7.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.