変数を他の関数と foreach の外側に渡す必要があります
function eri_add_custom_user_profile_fields( $user ) {
$sql="SELECT `pid`,
max(case when `meta_key` = 'nome' then `meta_value` end) as nome ,
max(case when `meta_key` = 'pagina' then `meta_value` end) as pagina ,
max(case when `meta_key` = 'punti' then `meta_value` end) as punti ,
max(case when `meta_key` = 'cpc' then `meta_value` end ) as cpc
FROM wp_usermeta
GROUP BY `pid`
ORDER BY cpc DESC";
global $wpdb;
$usermeta = $wpdb->get_results($sql) or die(mysql_error());
foreach ($usermeta as $post) {
echo $post->pid; //i want update the generated user id
echo $post->nome;
echo $post->pagina;
echo $post->punti;
echo $post->cpc;
$result = $post->punti-$post->cpc;
echo $result;
<input type="hidden" name="ptotali" id="ptotali" value="<?php echo $result; ?>" class="regular-text" />
<input type="submit" name="updateuser" id="updateuser" value="update" class="regular- text" />
}
}
function eri_save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
// Update and Save Field
update_usermeta( $pid, 'ptotali', $_POST['ptotali'] );
}
add_action( 'show_user_profile', 'eri_add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'eri_add_custom_user_profile_fields' );
add_action( 'personal_options_update', 'eri_save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'eri_save_custom_user_profile_fields' );
同じコードで pid を手動で入力すると、たとえば 3 のように pid 番号 3 が正しく更新されますが、変数 $pid が認識されません...何が問題なのですか?