通过添加onclick 事件到您的按钮:
<button id="updateMyUserMeta" name="updateMyUserMeta" onclick="window.location.href(\'http://example.com?my_custom_user_meta=true\');">Update</button>
 然后将此添加到
functions.php 你的主题。
/**
 * Updates the \'my_custom_user_meta\' field if the
 * user clicks the \'Update\' button.
 */
function update_my_custom_user_meta() {
  if (empty($_GET[\'my_custom_user_meta\']) {
    return;
  }
  $user_id = current_user_id();
  if (empty($user_id)) {
    return false;
  }
  update_user_meta( $user_id, \'my_custom_user_meta\', true); 
}
add_filter(\'init\', \'update_my_custom_user_meta\');
 更改
http://example.com 到您网站的URL并更改
my_custom_user_meta 到用户元字段的名称。
为了确保安全,您还应该adding nonce checks.