I am trying to use the wpdb->update() function to update a row in a database that has a custom PRIMARY KEY. Here is my wpdb->update() code:
$wpdb->update(
$table_name,
array(
$column => $value
),
array(
‘observation_id’ => $observation_id
),
array(
‘%s’, ‘%d’
),
array( ‘%d’ )
);
but I am getting the PHP error:
WordPress database error Unknown column ‘id’ in ‘where clause’ for query UPDATE
Am I missing something? In the 3rd argument for update() I am specifying to search by “observation\_id” and not “id”. Does WordPress automatically force searching by “id” under the hood?
This is part of a custom rest\_route, which I am hitting with the AJAX Query:
url: endpoint,
type: ‘PUT’,
data: {
observation_id: parseInt(observationId),
column: columnName,
value: value
},
headers: {
‘X-WP-Nonce’: wpApiSettings.nonce
},
​
The weird thing is that upon refreshing the page, the value pulled from the database is the updated value sent over the rest endpoint, but the AJAX response gives a \`parsererror\`.
​
Thank you for your help!
[ad_2]