0
我需要一個變量傳遞到其他功能外一個foreachPHP SQL WordPress的犯規更新,因爲可變無法識別
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沒有被識別...什麼是錯的?
mhh對不起,但我不明白我怎麼能定義一個變量值生成?你能舉個例子嗎?非常感謝, – nikz
我得到了你的意思,功能eri_save_custom_user_profile_fields($ user_id)而不是$ user_id我把$ pid?我tryed,但沒有作品... – nikz
好吧,wheres你的代碼位於?自定義函數,插件還是在發佈帖子的「頁面」上?否則'$ _POST ['your_post_val'];'將是空的。 – ScottMcGready