【问题标题】:Post view count not updating with WP Super Cache发布视图计数未使用 WP Super Cache 更新
【发布时间】: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


    【解决方案1】:

    每次添加新帖子时,请尝试通过 wordpress 插件中的设置清除缓存。还有一个设置可以在每次发布帖子时清除缓存。

    【讨论】:

    • 设置已经开启,新帖发布时已经在清缓存了。
    猜你喜欢
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 2017-06-23
    • 2018-04-14
    • 1970-01-01
    • 2018-07-25
    • 2015-08-25
    • 2012-07-30
    相关资源
    最近更新 更多