所以我有一个PHP页面,我从WordPress页面调用,以便我可以运行一个php INSERT。问题是,当我在下面调用wp_get_current_user();
时,PHP模板将不会定义当前用户ID。我有一个表单,并希望插入当前用户输入的内容以插入该用户的bio的数据库中。这是否意味着我需要将此变量从wordpress页面URL链接传递给此php模板我必须使用此表单?如果是这样,不确定格式/代码是这样做的。但理想情况下,如果这个模板能够以某种方式获得当前用户而无需发送它将是巨大的!
<?php
//connect
}
mysql_select_db("i80_wp1",$con);
// Get the current user's info
$current_user = wp_get_current_user();
if(isset($_POST['update'])) {
$UpdateQuery =
"UPDATE wp_usermeta SET author_bio='".$_POST['author_bio']."'WHERE
user_id=$current_user and author_bio='".$_POST['hidden']."'";
mysql_query($UpdateQuery, $con);
答案 0 :(得分:0)
访问任何外部php文件中的wordpress函数,将以下两行代码复制到php文件的顶部。
<?php $blogheader = explode("wp-content",$_SERVER["SCRIPT_FILENAME"]);
include $blogheader[0]."wp-blog-header.php"; ?>