Php 如何在wordpress中将用户名传递到将数据发送到数据库的表单中

Php 如何在wordpress中将用户名传递到将数据发送到数据库的表单中,php,mysql,wordpress,forms,Php,Mysql,Wordpress,Forms,我正在尝试通过表单将用户名传递到数据库: [insert_php] $current_user= wp_get_current_user(); $id= $current_user->user_login; [/insert_php] <input type="hidden" name="id" value="[insert_php]$id[/insert_php]"> 然后在表单中输入: <input type="hidden" name="id" value=

我正在尝试通过表单将用户名传递到数据库:

[insert_php]
$current_user= wp_get_current_user();
$id= $current_user->user_login; 
[/insert_php]


<input type="hidden" name="id" value="[insert_php]$id[/insert_php]">
然后在表单中输入:

<input type="hidden" name="id" value="<?php $id; ?>">
试试这个:

global $id;

全局声明它应该是解决办法。

我有一个表单,它工作正常,只有隐藏值无法通过。您试图将$id设置为什么?在wordpress中,当我在表单之前回显$id时,它打印出值,所以它不是空的。我在表单之前已经设置了$id,我只需要将它通过表单,但这并不是一个全球性的变量。看看我的答案
global $id;