I need to update 2 users fields at the same time, giving 8 points to the user who is voting and 8 points to the team.
I use the following code:
<input type="hidden" name="ptolti" id="ptolti" value="<?php echo $puntitolti; ?>" class="regular-text" />
<input type="hidden" name="ptotali" id="ptotali" value="<?php echo $risultato; ?>" class="regular-text" />
<?php
function nico_save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
global $wpdb;
update_usermeta( $user_id , 'ptotali', $_POST['ptotali'] );
update_usermeta( $id_utente , 'ptotali', $_POST['ptolti'] );
}
?>
It works for the user_id which is voting for the team, so when I click “vote” I get 8 points and if I click again my points go to 16 and its correct, but the team points are not updated.
Because you are not passing the correct key for the team points, you are passing the same key for user_id and for team_id. I guess that ptolti is the key for the team?
I tried update manually the id_utente doing:
and that works, so I suppose the variable $id_utenti is not recognized… but not understand why… because outsite the foreach the variable is recognized well and output is 3..
probably because I’m trying to put the variable inside an other function…. so how can I solve?