**已解决** 我没有在窗体处理器中需要Wordpress。添加此线在顶部固定它(总是最简单的事情,对吧!?): require_once(explode("wp-content" , __FILE__)[0] . "wp-load.php");
Wordpress update_user_meta不能正常工作
我创建了一个客户的网站自定义前端的空间,我添加了其他用户的方式以最喜欢该配置文件。 (请不要建议类似的东西BuddyPress的或其它插件 - 我已经试过了十几,和他们都没有所有我需要的功能感谢。):)
反正....这里是概述。我希望这很清楚。比方说,用户1查看用户10
- 在数据库中的配置文件,用户1有一个名为favorite_10场,可设置为“yes”或“no”(或空)
- 当有人点击另一个用户配置文件中的“收藏”按钮,它将运行一个简单的脚本,将值从“是”更改为“否”或反之亦然
就是这样。我认为这是一个非常好的解决方案,但表格处理脚本正在打破update_user_meta
一行。
我们走吧。
foreach($sitterlist as $sitteritem) {
$code = 'favorite_'.(esc_html($sitteritem->ID));
$key = esc_html($sitteritem->ID);
$favorite[$key] = get_the_author_meta($code, $currentuser);
}
$is_favorite=null;
if ($favorite[$usertosearch]=='yes') {
$is_favorite = true;
} else {
$is_favorite = false;
}
?>
<form method="post" action="updatefavorite.php">
<input type="hidden" value="<?php echo $usertosearch; ?>" name="usertosearch" id="usertosearch">
<input type="hidden" value="<?php echo $currentuser; ?>" name="currentuser" id="currentuser">
<input type="hidden" value="<?php echo $is_favorite; ?>" name="is_favorite" id="is_favorite">
<button type="submit" id="favoritebutton" name="favoritebutton"><span>Favorite</span></button>
</form>
这里是updatefavorite.php
<?php
if(isset($_POST['favoritebutton'])) {
$currentuserid = $_POST['currentuser'];
$currentprofileid = $_POST['usertosearch'];
$currentfavorite = $_POST['is_favorite'];
$code = 'favorite_'.$currentprofileid;
if ($currentfavorite) {
$currentfavorite = 'no';
} else {
$currentfavorite = 'yes';
}
update_user_meta($currentuserid,$code,$currentfavorite);
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
经过大量的测试和调试的,我已经想通了,它打破在update_user_meta
...但我不知道为什么。
谢谢!
只是一句话,有人敲出了相当多的代码来解决你所描述的问题,你还没有认识到他们的努力与upvotes /接受答案。至于这个问题,你有一个在你的HTML错误,你有一个空间名称属性,并没有空间在您的PHP – David
谢谢。我还没有找到这些帖子,而且我搜索了很多 - 并且可能读了一打 - 但我会继续寻找。感谢您捕获该类型-o。我不认为这是问题,但我会解决它(在我的调试中,我已经成功调用脚本并通过脚本的每个部分获取,直到update_user_meta,因此我相当确信这是问题所在)。 更新:该类型o实际上不在我的代码中。只在帖子里。 – NYCjbd
你有没有在你的自定义文件中加载wordpress? – David