在wordpress中获取用户名并使用表单发布

时间:2012-02-27 20:03:07

标签: php forms wordpress

在wordpress中使用此代码:<input hidden="hidden" type="text" value="<?php wp_get_current_user(); ?>" name="USER" />

我正在尝试将当前登录的用户(wordpress)发布到另一个php文件。它适用于我所有其他输入,但不知何故USER返回空白。关于为什么会发生这种情况的任何想法?

感谢您的建议。

2 个答案:

答案 0 :(得分:0)

您使用了input元素的无效属性:没有名为hidden的属性。此外,您希望属性type等于hidden。试试这个:

<input type="hidden" value="<?php wp_get_current_user(); ?>" name="USER" />

另见the list of valid properties of the input element

答案 1 :(得分:0)

这似乎有效:)

<?php
$user = get_current_user();

   echo $current_user->user_login;

?>