How to get last updated row or ID in wordpress.
Like : $wpdb->insert_id;
How to get last updated row or ID in wordpress.
Like : $wpdb->insert_id;
I had the same problem.
There is no equivalent function.
$wpdb->insert_id
works only after$wpdb->insert
Alternative way
If it’s an update, you can either get the id with a query based on the data you have got, or most of the time, you should have already got the id before update it.
global $wpdb;
$data = array(
'first_name' => "John",
'last_name' => "Doe"
);
$where = array(
'id' => $my_id
);
$res_update = $wpdb->update( $wpdb->prefix . "my_table", $data, $where );
if( $res_update === false ){
error_log( 'my error');
}
return $my_id;