wpdb::delete()
Deletes a row in the table.
Examples:
$wpdb->delete( 'table', array( 'ID' => 1, ) ); $wpdb->delete( 'table', array( 'ID' => 1, ), array( '%d', ) );
Method of the class: wpdb{}
No Hooks.
Return
Int|false
. The number of rows deleted, or false on error.
Usage
global $wpdb; $wpdb->delete( $table, $where, $where_format );
- $table(string) (required)
- Table name.
- $where(array) (required)
- 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.
- $where_format(string[]|string)
- 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 $data will be treated as strings unless otherwise specified in wpdb::$field_types.
Default: null
Examples
#1 Example of deleting data from the database
// Delete row with field ID=1 from table table $wpdb->delete( 'table', [ 'ID' => 1 ] ); // Let's specify the format of the value $where $wpdb->delete( 'table', [ 'ID'=>'1' ], [ '%d' ] ); // 1 will be treated as (int) (%d).
#2 Multiple "where" and "type"
$where = [ 'UID' => 248, 'File' => "C:\file.txt" ]; $where_format = [ '%d', '%s' ]; $wpdb->delete( $table, $where, $where_format );
Notes
- See: wpdb::prepare()
- See: wpdb::$field_types
- See: wp_set_wpdb_vars()
Changelog
Since 3.4.0 | Introduced. |