Short Code To Update Meta Values Via PHP
-
I am trying to update the meta values of a user using php code. Is there something I am missing trying to do this? Here is a bit of my code that I use to do this:
#Retrieves Current User's ID $user_ID = get_current_user_id(); #Retrieves Amount Left To Pay $lefttopay = get_user_meta($user_ID, Left_To_Pay, true); #Gets This Payment Amount $lastpayamt = get_user_meta($user_ID, Last_Pay_Amount, true); #Subtracts This Payment From Total $newlefttopay = $lefttopay - $lastpayamt; #Changes Left To Pay Amount To Above Amount update_user_meta($user_ID, Left_To_Pay, $newlefttopay, true);
So this chunk of code retrieves the user id. Then plugs it into the next line to get the Left_To_Pay meta data (which is at 10 by the way), it then gets the Last_Pay_Amount meta data which was set to 1 further up in the code. It then subtracts 1 from 10 and then updates the Left_To_Pay meta data to 9.
When I run this code and then go to edit the meta data for a specific user, I see no change for the user. Any help? I assume all the update and get formats are similar so if there is a problem up you should see the same problem in the code above.
Thanks in advance.
- The topic ‘Short Code To Update Meta Values Via PHP’ is closed to new replies.