Deletes a row in the table.
Examples:
$wpdb->delete(
'table',
array(
'ID' => 1,
)
);
$wpdb->delete(
'table',
array(
'ID' => 1,
),
array(
'%d',
)
); $tablestringrequired
$wherearrayrequired
$where_formatstring[]|stringoptional
'%d', '%f', '%s' (integer, float, string).Default:null
public function delete( $table, $where, $where_format = null ) {
if ( ! is_array( $where ) ) {
return false;
}
$where = $this->process_fields( $table, $where, $where_format );
if ( false === $where ) {
return false;
}
$conditions = array();
$values = array();
foreach ( $where as $field => $value ) {
if ( is_null( $value['value'] ) ) {
$conditions[] = "`$field` IS NULL";
continue;
}
$conditions[] = "`$field` = " . $value['format'];
$values[] = $value['value'];
}
$conditions = implode( ' AND ', $conditions );
$sql = "DELETE FROM `$table` WHERE $conditions";
$this->check_current_query = false;
return $this->query( $this->prepare( $sql, $values ) );
}
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/delete