I am modifying an existing plugin by creating an extension to it. I am trying to update a row with basic info just to test to see if the $wpdb->update works, but even using plain values it seems to get stuck. Please take a look at this image. The form keeps showing the working symbol but when I look in the database a new row has already been created, so the post went through. I think it is getting stuck on my lines of code below. I read some other similar questions on this website where people solved the problem by putting the $data
and $where
terms into variables, so I did that. It made it easier to read, but it doesn’t seem to fix my problems.
$amount_field_col = array('post_amount' => '12.15');
$where_clause = array('ID' => '30');
$wpdb->update('wp_posts', $amount_field_col, $where_clause);
Any idea why it might not be updatig the row and why it could be getting stuck? The overall goal here is that I made a new field to an existing form and I want to be able to take inputs to the form and plug it into a new column I made in PHPMyAdmin called post_amount
.
I think I figured it out. The function that this code is in did not have
global $wpdb;
declared. I simply added that in above my code and it correctly update the row with ID = 30.Question for more experienced people – So by default, does each function forget about all other variables previously declared, even GLOBALS? I see in this plugin code that this variable was declared in its activation.php file, so I thought it would “remember” that $wpdb was declared.