【发布时间】:2018-07-31 05:06:46
【问题描述】:
我使用此代码来获取帖子计数,并且在我安装并启用 WP Super Cache 之前工作正常。一旦我安装并设置了 WP Super Cache,帖子数就不再更新了。
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
请告诉我如何解决这个问题。
【问题讨论】:
标签: wordpress view count browser-cache