[wp-trac] [WordPress Trac] #53297: Bug in wpdb update

WordPress Trac noreply at wordpress.org
Sat May 29 21:23:05 UTC 2021


#53297: Bug in wpdb update
--------------------------+------------------------------
 Reporter:  ttodua        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Database      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by pbiron):

 Hi @ttodua.  In your case, you need to use the 4th parameter (`$format`)
 of [https://developer.wordpress.org/reference/classes/wpdb/update/
 wpdb:update()] to specify the "format" of the data.

 For example:

 {{{#!php
 $wpdb->update(
    'any_custom_table',
    array(
       'parent' => 'hellow world',
       'other'  => 'xyz',
    ),
    array(
       '%s',
       '%s',
    )
 );
 }}}

 Why?  Because `wp_posts` has a column named `post_parent` (with an "alias"
 of `parent`). `wpdb`, by default, treats **any** column named `parent` as
 being an integer (even in custom tables).

 For details of all column names whose values are not treated as strings,
 see [https://developer.wordpress.org/reference/functions/wp_set_wpdb_vars/
 wp_set_wpdb_vars()].

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53297#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list