我使用此代码获取帖子数,并且在安装并启用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);
请让我知道如何解决此问题。
答案 0 :(得分:0)
每次添加新帖子时,请尝试通过wordpress插件中的设置清除缓存。还有一个设置,用于在每次发布文章时清除缓存。