我正在创建投票后系统,允许访问者评分(从1到5)。如果用户登录,或者没有安装任何缓存插件,它工作正常。但对于激活了缓存插件的客户(WP超级缓存),它无法正常工作。
有人可以帮助我让访客用户也能使用吗?我想它需要一些Ajax / JavaScript?
<form method='POST' action="">
<input type="hidden" name="rate" value=2>
<input type=submit value=2>
</form>
<form method='POST' action="">
<input type="hidden" name="rate" value=3>
<input type=submit value=3>
</form>
<form method='POST' action="">
<input type="hidden" name="rate" value=4>
<input type=submit value=4>
</form>
<form method='POST' action="">
<input type="hidden" name="rate" value=5>
<input type=submit value=5>
</form>
<? php
if (isset($_POST['rate'])) {
if ($_POST['rate'] == '1') {
$rate = get_post_meta($post - > ID, 'up', true);
$rate = $rate + 1;
update_post_meta($post - > ID, 'up', $rate);
$total = get_post_meta($post - > ID, 'total', true);
$ratetotal = $total + 1;
update_post_meta($post - > ID, 'total', $ratetotal);
}
if ($_POST['rate'] == '2') {
$rate = get_post_meta($post - > ID, 'up', true);
$rate = $rate + 2;
update_post_meta($post - > ID, 'up', $rate);
$total = get_post_meta($post - > ID, 'total', true);
$ratetotal = $total + 1;
update_post_meta($post - > ID, 'total', $ratetotal);
}
if ($_POST['rate'] == '3') {
$rate = get_post_meta($post - > ID, 'up', true);
$rate = $rate + 3;
update_post_meta($post - > ID, 'up', $rate);
$total = get_post_meta($post - > ID, 'total', true);
$ratetotal = $total + 1;
update_post_meta($post - > ID, 'total', $ratetotal);
}
if ($_POST['rate'] == '4') {
$rate = get_post_meta($post - > ID, 'up', true);
$rate = $rate + 4;
update_post_meta($post - > ID, 'up', $rate);
$total = get_post_meta($post - > ID, 'total', true);
$ratetotal = $total + 1;
update_post_meta($post - > ID, 'total', $ratetotal);
}
if ($_POST['rate'] == '5') {
$rate = get_post_meta($post - > ID, 'up', true);
$rate = $rate + 5;
update_post_meta($post - > ID, 'up', $rate);
$total = get_post_meta($post - > ID, 'total', true);
$ratetotal = $total + 1;
update_post_meta($post - > ID, 'total', $ratetotal);
}
}
$score = get_post_meta($post - > ID, 'up', true);
$number_of_votes = get_post_meta($post - > ID, 'total', true);
$average = round($score / $number_of_votes, 1);
echo $average;;
echo ' / 5 ';
echo " - ".get_post_meta($post - > ID, 'total', true)." votes"; ?>