我会更新从foreach
循环生成的特定ID的值字段。
$sql = "SELECT `user_id`,
max(case when `meta_key` = 'link' then `meta_value` end) as link ,
max(case when `meta_key` = 'team' then `meta_value` end) as team ,
max(case when `meta_key` = 'points' then `meta_value` end ) as points
FROM wp_usermeta GROUP BY `user_id` ORDER BY points DESC";
global $wpdb;
$usermeta = $wpdb->get_results($sql) or die(mysql_error());
foreach ($usermeta as $post)
echo "<li> name: ". $post->team ."<br/> link: ". $post->link . "<br/> obtain: " .$post->points. " points </li>" ;
页面上的输出如下所示:
球队: 曼彻斯特 链接: manunited.co.uk 积分: 8
用户可以投票给团队,团队获得 8 分,所以我需要这样的更新。
update_usermeta( $post->user_id , 'points', $_POST['points'] );
问题是在foreach之外无法识别变量$post->user_id
,但我需要团队的特定ID来更新它。
谢谢大家。
我相信
你需要声明:
global $post;
在 foreach 循环之外。