What’s the difference between {php}$wpdb->replace{/php} and {php}$wpdb->update{/php} (or other methods)? {php}$wpdb->replace{/php} will perform a delete and an insert. But remember: if there are one or more rows in the table that share a value for the ‘unique_index’, all of the rows that have that value will be deleted and just one new row will be inserted.
Example code to replace a row in a WordPress table that has three columns:
[php]
$wpdb->replace(
‘wp_table’,
array(
‘unique_index’ => ‘value1’,
‘column2’ => 123,
‘column3’ => $var,
),
array(
‘%s’,
‘%d’,
‘%s’
)
);
[/php]
Share/Ask