#53297 closed defect (bug) (invalid)
Bug in wpdb update
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Database | Keywords: | |
| Focuses: | Cc: |
Description
To test a simple example:
$wpdb->update('any_custom_table', ['parent'=>"hello world", "other"=>"xyz"], $WhereArray );
Even though, in the table, the "parent" column is "text" type (non numeric), wordpress still converts the value and instead of "hello world" the numeric value is being inserted (i.e. 0 in that case, however, if you pass "123456_hello", it inserts 123456.
Change History (4)
#3
@
5 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
My pleasure. I'm going to close this ticket.
#4
@
5 years ago
For anyone finding this ticket in the future, let me correct one thing in my answer above.
The reason columns named parent are treated as integers is because wp_term_taxonomy has a column named parent which is an integer (and not because parent is an "alias" of the post_parent column in wp_posts). My bad.
The rest of the answer (about using the $format parameter) is correct :-)
Note: See
TracTickets for help on using
tickets.
Hi @ttodua. In your case, you need to use the 4th parameter (
$format) of wpdb:update() to specify the "format" of the data.For example:
$wpdb->update( 'any_custom_table', array( 'parent' => 'hellow world', 'other' => 'xyz', ), array( '%s', '%s', ) );Why? Because
wp_postshas a column namedpost_parent(with an "alias" ofparent).wpdb, by default, treats any column namedparentas being an integer (even in custom tables).For details of all column names whose values are not treated as strings, see wp_set_wpdb_vars().