您需要一个ajax调用来执行服务器端功能。
因此,在stampme()中,在显示消息之前或之后,您需要以下内容:
jQuery.ajax({
url: ajaxurl,
data: {
action: \'WPSE_339452_update_user_meta\',
value: jQuery(\'input[name="inputcode"]\').val() //if that\'s the value you want to save...
},
success: function (result) {
console.log(result)
// whatever JS based on the result that can be true / false
},
error: function (errorThrown) {
console.log(errorThrown);
}
})
在服务器端,您必须定义自定义ajax挂钩来更新user\\u元值:
function WPSE_339452_update_user_meta (){
$_value=$_REQUEST[\'value\'];
$_user=wp_get_current_user();
die(update_user_meta($_user->ID,"my_user_meta_field",$_value));
/* the return of update_user_meta can be
true= value updated,
false = value not updated since it was the same as the old value
in this case it won\'t update */
}
add_action ("wp_ajax_WPSE_339452_update_user_meta","WPSE_339452_update_user_meta");